1

I have a big bitmap, created with Bitmap.createBitmap(). Is there any sense in writing

bitmap = null;

just before

bitmap = Bitmap.createBitmap();

to let the GC use the memory occupied with the old bitmap while constructing the new bitmap.

The API level is 11.

Thank you.

RobinBobin
  • 555
  • 7
  • 17

2 Answers2

0

bitamp = null; will not ensure that GC will release the memory occupied by bitmap object. Brcause as Bitmap is a final class so priority of final object is very low for GC. Use bitmap.recycle() method to ensure for Garbage collection(GC).

Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
0

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

Look at the video around 11:23. The guy talks about bitmap memory management

Its left to the garbage collector to free memory. Instead of bitmap = null use bitmap.recycle() on andorid 2.3.3 and lower. Use BitmapFactory.Options.inBitmap on 3.0 and higher

Android - Bitmap and memory management?

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

On android 2.3.3 and lower

On Android 2.3.3 (API level 10) and lower, using recycle() is recommended. If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible.

On android 3.0 and higher

The bitmap pixel data is stored on the heap

Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content. This means that the bitmap's memory is reused, resulting in improved performance, and removing both memory allocation and de-allocation.

Also check this might help

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256