5

Need some help for understanding the recycle() method of the class Bitmap.

If I have a Bitmap[] named "bmp" for example whats the difference between doing

Bitmap[i].recycle()

And

Bitmap[i]=null;

Whats the best option? Should I call both?

Thanks

EboMike
  • 76,846
  • 14
  • 164
  • 167
Addev
  • 31,819
  • 51
  • 183
  • 302

3 Answers3

4

According to this question, bitmap data is stored in native memory rather than in the Dalvik heap. You should call recycle() to free the memory the bitmap is stored in once you are finished with it. It's good practice to set it to null afterwards, although this is somewhat redundant.

See also the api: http://developer.android.com/reference/android/graphics/Bitmap.html#recycle()

Community
  • 1
  • 1
shanet
  • 7,246
  • 3
  • 34
  • 46
3

I think you mean recycle, but recycling actually releases the object from memory, whereas setting it to null still keeps it in memory.

Jon Martin
  • 3,252
  • 5
  • 29
  • 45
0

The Android Training class, "Displaying Bitmaps Efficiently", offers some great information for understanding and dealing with loading and recycling Bitmaps.

hcpl
  • 17,382
  • 7
  • 72
  • 73