Do we have to explicitly recycle the bitmap if we don't need it?

半世苍凉 提交于 2020-01-04 08:16:11

问题


Bitmap has a recycle method, but do we have to invoke it explicitly if we don't need it any more?

For example, an ImageView has a bitmap now. When user click a button, it will set a new bitmap to the ImageView.

Do we have to recycle the original bitmap before assign the new one?


回答1:


yes you have if you are targeting devices with Android older the 3.0. That's will avoid you to incour in the OutOfMemoryException.

Note: Before android 3 the Bitmap memory is allocated in the native heap. The java object will retains low memory from the GC perspective.



来源:https://stackoverflow.com/questions/12533001/do-we-have-to-explicitly-recycle-the-bitmap-if-we-dont-need-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!