Skip to content Skip to sidebar Skip to footer

How To Release Bitmap Memory In Android

In our program wo use lots of images,we unbindDrawables in eyery Activity and Fragment as below protected void unbindDrawables(View view) { if (view != null) { if

Solution 1:

You must call bitmap.recycle() to release the native memory allocated when you decoded the bitmap.

And of course you must have to take care of the life cycle of the bitmap. To release it at proper time. A better solution is to use some image loader class to take care of it. See https://github.com/nostra13/Android-Universal-Image-Loader

Solution 2:

call recycle on the bitmap and remove any references to your bitmap objects

Solution 3:

The thing is that in the pre-Honeycomb versions of Android the memory for bitmaps was (is) allocated from unmanaged memory, which creates all sorts of problems. It is still released but from the finalizer of the bitmap object implementation. Which means that it will take at least 2 passes of GC to collect it. Also if for whatever reason the finalizer fails to execute - you got the picture. Another thing is - it is really difficult to trace - DDMS does not see it and neither does MAT.

For Android 3.0 this has been changed and bitmaps are implemented over managed byte arrays, but for the older phones...

Post a Comment for "How To Release Bitmap Memory In Android"