ksnowlv

回顾过去,总结以往;立足现在,铭记当下;技术为主,笔记而已.

Trying to Use a Recycled Bitmap android.graphics.Bitmap@bffc9a0解决方案

| Comments

最近项目中出现了一批“trying to use a recycled bitmap android.graphics.Bitmap@bffc9a0”异常,是什么原因导致的呢?

原因:图片在回收后,依然有一些地方引用该Bitmap.

解决方案:可以在使用Bitmap的地方解除对Bitmap引用后再回收。

如果使用的是ImageView,可以在回收时,先解除ImageView对Bitmap的使用,再回收Bitmap。例如:

1
2
3
4
5
6
7
8
9
10
 protected void onDestroy() {

        mStarterImageView.setImageBitmap(null);
        if (null  != mStartBitmap&& !mStartBitmap.isRecycled()) {
            mStartBitmap.recycle();
            mStartBitmap = null;
        }

        super.onDestroy();
   }

Comments

comments powered by Disqus
Included file 'custom/after_footer.html' not found in _includes directory