Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:16:23+00:00 2026-05-26T13:16:23+00:00

My app can load quite large images. In an effort to be memory-conservative, I’m

  • 0

My app can load quite large images. In an effort to be memory-conservative, I’m attempting to use a temporary bitmap to load and another for the final image after transformation:

.....
finalBitmap.recycle();
finalBitmap = null;
Bitmap tempBitmap  = BitmapFactory.decodeStream(fin, ...);
finalBitmap = Bitmap.createBitmap(tempBitmap, ....);
imgview.setImageBitmap(finalBitmap);
.....

Now, at this point we’re done with tempBitmap, which was only needed to transport the decoded Bitmap to the transformation step in createBitmap. So:

.....
tempBitmap.recycle();
tempBitmap = null;
.....

And… it crashes with a “trying to use a recycled bitmap” error specifically because of the recycling of tempBitmap. tempBitmap wasn’t displayed and is only used right there.

What’s going wrong here? Should I just use “finalBitmap” throughout and rely on createBitmap to manage it (finalBitmap = Bitmap.createBitmap(finalBitmap , ….))? I fail to see what ongoing dependency on tempBitmap there would be that would cause such a failure.

Edit: Yes, the null assignment seems to result in the appropriate, eventual garbage collection, but I’m mystified as to why recycle() on a temp Bitmap is so problematic in this case. I get the impression that createBitmap() is holding a reference to it but why, and for how long?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:16:24+00:00Added an answer on May 26, 2026 at 1:16 pm

    Straight from the Android documentation:

    Returns an immutable bitmap from the specified subset of the source
    bitmap. The new bitmap may be the same object as source, or a copy may
    have been made.

    It seems that the createBitmap functions have the potential to re-use the bitmap that you provided. If that is the case, then you shouldn’t recycle the temporary bitmap since your final bitmap is using it. One thing you can do is

    if(tempBitmap != finalBitmap) {
       tempBitmap.recycle();
    }
    

    That should only recycle the tempBitmap when it isn’t the same as the finalBitmap. At least that seems to be what the documentation is implying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My iPhone app can't seem to use soft keyboards that doesn't use the US-like
An iPad app can support inclusion of launch images in both orientations; presumably, if
I just got this quite large CakePHP app (about 20k lines of code), which
I have an Scrollview in my app that has quite a large amount of
The users of my app can configure the layout of certain files via a
After update our iphone app can not access the keychain. The distribution certificate has
Each request in my web app can get one data access object instance (of
I need help with NinePatchDrawable: My app can download themes from the network. Almost
I have createn an app, this app can be found here Everything is working
Is there an API that my Google App Engine app can call when signed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.