首页 > 移动平台 > 详细

关于bitmap recycle trying to use a recycled bitmap android.graphics.Bitmap

时间:2015-07-21 12:52:07      阅读:201      评论:0      收藏:0      [点我收藏+]

在开发中,一直使用4.0以上手机作为测试机所以一直没有出现这个问题,今天换了2.3版本的手机,出现了这个错误:

trying to use a recycled bitmap android.graphics.Bitmap


后检查代码,我的图片回收代码是介个样子的:

public static void recycle(View view) {
if (null == view) {
return;
}


BitmapDrawable bd = (BitmapDrawable) view.getBackground();
if (null == bd) {
return;
}

Bitmap bm = bd.getBitmap();
if (null != bm && !bm.isRecycled()) {
bm.recycle();
}
}


即在我回收了图片后,这个View对象还在引用这个图片,导致出现这个问题,后修改为:

public static void recycle(View view) {
if (null == view) {
return;
}

BitmapDrawable bd = (BitmapDrawable) view.getBackground();
if (null == bd) {
return;
}


view.setBackgroundDrawable(null);
Bitmap bm = bd.getBitmap();
if (null != bm && !bm.isRecycled()) {
bm.recycle();
}
}


设置背景图片为空,取消对图片的引用再去回收。


版权声明:本文为博主原创文章,未经博主允许不得转载。

关于bitmap recycle trying to use a recycled bitmap android.graphics.Bitmap

原文:http://blog.csdn.net/fkepgydhbyuan/article/details/46982609

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!