Search code examples
androidbitmapgridrecycle

Android bitmap recycle


I am having an issue with bitmap recycle. I am displaying the bitmaps in a grid view . I have about 40-50 thumbnails. when I down load the thumb image from the url I cached it to disk. Set the bitmap on ImageView and call bitmap.recycle(). BUt I keep getting recycled bitmap cannot be used.

Any ideas on what might be happening. Thanks for your help. I am re-using the 'convert-view' in the getView() of the ImageAdapter

Regards -Chandu


Solution

  • My understanding of this is, you can't recycle a bitmap that is still being used. Furtheremore, as you are using an adpatable view you don't even know when an image will no longer be used.

    The solution is to use weak references with the bitmaps to allow the carbage collector to take care of freeing up that memory when it is no longer needed.

    Here is a guide: http://developer.android.com/training/displaying-bitmaps/process-bitmap.html