Do I need to recycle BitmapDrawable

According to http://developer.android.com/training/displaying-bitmaps/manage-memory.html

In Android 2.3.3 (API level 10) and lower, using recycle () recommended. If you display a large amount of raster data in your application, you are likely to encounter OutOfMemoryError errors. The Recycle () method allows the application to recover memory as soon as possible.

I was wondering, for BitmapDrawable I need to do a clean up, like

bitmapDrawable.getBitmap().recycle()

if it is no longer needed?

+4
source share
2 answers

It is better to recycle bitmaps when not in use. You can load the bimaps in onResume () and recycle the same in onPause ().

So, to reduce memory consumption and avoid memory leaks, it is better to use bitmap images when not in use.

Also check out the discussion of memory management in the link

http://www.youtube.com/watch?v=_CruQY55HOk

Edit:

The quote forms the link you posted. (You can check under the heading Memory Management on Android 2.3.3 and below)

On Android 2.3.3 (API level 10) and below, it is recommended to use recycle () .

Starting with HoneyComB bitmaps, they are stored in HEAP instead of their own bitmap heap.

Android 3.0 (API level 11) represents the BitmapFactory.Options.inBitmap field. If this option is set, the decoding methods that accept the Parameters object will try to reuse the existing bitmap when loading the content. This means that bitmap memory is reused, which leads to improved performance and the removal of both memory allocation and de-allocation

http://developer.android.com/training/displaying-bitmaps/manage-memory.html

+1
source

The documentation tells you

This is an extended call and usually does not need to be called since the normal GC process will free this memory when they are no longer referenced by this bitmap.

So, I will go with: no, you do not need to call it. Free up your bitmap resources, however, by clearing the links you have.

The link you added mainly talks about why it could help before and after:

In Android 2.3.3 (API level 10) and below, the backup pixel data for the bitmap is stored in its own memory. It is separated from the bitmap that is stored in the Dalvik heap. The pixel data in the memory is not released in a predictable manner, which potentially causes the application to briefly exceed memory limits and crash. Starting with Android 3.0 (API level 11), pixel data is stored on the Dalvik heap along with the corresponding bitmap.

+2
source

All Articles