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

  • Home
  • SEARCH
  • 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 8274879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:52:55+00:00 2026-06-08T07:52:55+00:00

I have to free memory occupied by bitmaps. So I’m calling recycle() on all

  • 0

I have to free memory occupied by bitmaps. So I’m calling recycle() on all of them, when my activities finish.

These bitmaps are always used in drawables, either as background property or source (case of ImageView) property.

But the problem is, when later another activity has a view that also uses these bitmaps, it will show

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap.

What can I do, I can’t keep the bitmaps in memory only because maybe the user starts, at some point later, an activity which uses them. How do I tell the bitmaps to free memory and also please be possible to be used later again?

  • 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-06-08T07:52:59+00:00Added an answer on June 8, 2026 at 7:52 am

    The solutionis to initialize the Bitmap and View using this:

    Bitmap b = BitmapFactory.decodeResource(resources, R.drawable.mybitmap);
    view.setBackgroundDrawable(new BitmapDrawable(b));
    

    This does not work for XML bitmaps although. But the bitmap should be retrievable from the view.

    Having the bitmap instance in memory, it’s possible to call recycle() on it to free memory immediatly.

    And before recycling the bitmap it has to be ensured that it’s not referenced by any view anymore – setting the references of the drawable / view to null. Otherwise the exception will be thrown. In order to do this it’s necessary to keep track of the views which are referencing a bitmap and null all the references before recycling it.

    So my actual problem was not reusing the bitmap. The problem was recycling the bitmap while is still referenced by a view.

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

Sidebar

Related Questions

Suppose that I have used a free() function to free a memory that,for many
Just curious. If you have 4Gb of free memory and you create 10k of
Suppose i have a LPSTR variable. How do i free the memory after using
I have a free shipping price rule which is configured like this: All customer
I have a simple question hopefully - how does one free memory which was
I have the following code. It gives me a problem with free memory, but
I know that in PHP you don't have to free memory. Is it reached
How can I obtain this information: Total Memory Free Memory Memory used by current
I have a multimap from which I want to free the memory allocated to
i'm trying to release UIWebView object but it not free memory. is it have

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.