Bitmap leftBitmap = ((BitmapDrawable) iv.getDrawable()).getBitmap();
ivLeftAvatar.setImageDrawable(null);
if (leftBitmap != null && !leftBitmap.isRecycled()){
leftBitmap.recycle();
leftBitmap = null;
}
System.gc();
主要是对Imageview 执行<pre name="code" class="java">setImageDrawable()方法,将imageview内的bitmap清空。当然这里最好回收下bitmap
本文介绍了一种有效的方法来清除ImageView中持有的Bitmap资源,并确保Bitmap被正确回收以避免内存泄漏。通过使用setImageDrawable方法将ImageView设置为空,然后检查并回收Bitmap资源。
286

被折叠的 条评论
为什么被折叠?



