我们有明确的回收位图,如果我们不需要它? [英] Do we have to explicitly recycle the bitmap if we don't need it?
问题描述
位图有一个回收
方法,但这样做,我们必须显式调用它,如果我们不需要它了?
Bitmap has a recycle
method, but do we have to invoke it explicitly if we don't need it any more?
例如,的ImageView
现在有一个位图。当用户点击一个按钮,它会设置一个新的位图到ImageView的。
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?
推荐答案
是的,你有,如果你是的Android
年龄越大 3.0 <瞄准装置/ code>。这将避免你到incour的
OutOfMemoryException异常
。
yes you have if you are targeting devices with Android
older the 3.0
. That's will avoid you to incour in the OutOfMemoryException
.
请注意:在的Android 3.0
的位图存储在本地堆中分配。在Java对象将保留从GC角度低内存。
Note: Before android 3
the Bitmap memory is allocated in the native heap. The java object will retains low memory from the GC perspective.
这篇关于我们有明确的回收位图,如果我们不需要它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!