开发者

Bitmap recycle() in java Android

开发者 https://www.devze.com 2023-03-25 22:10 出处:网络
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

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


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()


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消