关于bitmap recycle trying to use a recycled bitmap android.graphics.Bitmap
在开发中,一直使用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的更多相关文章
- void android.graphics.Bitmap.recycle()
void android.graphics.Bitmap.recycle() Free up the memory associated with this bitmap's pixels, and ...
- Canvas: trying to use a recycled bitmap android.graphics.Bitmap@XXX
近期在做和图片相关显示的出现了一个问题,整理一下思路.分享出来给大家參考一下: Exception Type:java.lang.RuntimeException java.lang.RuntimeE ...
- int android.graphics.Bitmap.getRowBytes()
int android.graphics.Bitmap.getRowBytes() Return the number of bytes between rows in the bitmap's pi ...
- java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@412d7230
近期遇到了如标题这种错误,再次记录解决方法.本文參考帖子: http://bbs.csdn.net/topics/390196217 出现此bug的原因是在内存回收上.里面用Bitamp的代码为: t ...
- Android java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@412d7230
近期遇到了如标题这种错误,再次记录解决方法.本文參考帖子: http://bbs.csdn.net/topics/390196217 出现此bug的原因是在内存回收上.里面用Bitamp的代码为: t ...
- Bitmap recycle()
Bitmap调用recycle? When? Bitmap有一个recycle方法,意思非常easy,回收Bitmap的空间. Q 1: Bitmap是否有调用recycle方法的必要性? A: 嵌入 ...
- 关于android 使用bitmap的OOM心得和解决方式
android开发,从2010年開始学习到如今的独立完毕一个app,这漫长的四年,已经经历了非常多次bug的折磨.无数次的加班训练.然而,自以为自己已经比較了解android了,却近期在一个项目上.由 ...
- Android笔记--Bitmap
Android | Bitmap解析 Android中Bitmap是对图像的一种抽象.通过他可以对相应的图像进行剪裁,旋转,压缩,缩放等操作.这里循序渐进的一步步了解Bitmap的相关内容. 先了解B ...
- Android笔记——Bitmap自动取色(纯搬运)
2015/6/12更新:发现一个更好的,带demo https://github.com/MichaelEvans/ColorArt 说明: 这个是一个老外写的自动自动从bitmap中取主色与第二主色 ...
随机推荐
- WordPress漏洞扫描工具WPScan
WordPress漏洞扫描工具WPScan WordPress是主流的PHP网站模版,以构建博客而闻名.WordPress可以通过安装插件和主题的方式扩展功能,这也带来的安全隐患.WordPres ...
- CSU - 1334 -好老师(STL-map用法)
https://cn.vjudge.net/contest/157163#problem/E #include<map> #include<queue> #include< ...
- [P4064][JXOI2017]加法(贪心+树状数组+堆)
题目描述 可怜有一个长度为 n 的正整数序列 A,但是她觉得 A 中的数字太小了,这让她很不开心. 于是她选择了 m 个区间 [li, ri] 和两个正整数 a, k.她打算从这 m 个区间里选出恰好 ...
- 【拓扑排序】Genealogical tree
[POJ2367]Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5696 Accep ...
- BZOJ 2467 [中山市选2010]生成树(组合数学)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2467 [题目大意] 有一种图形叫做五角形圈.一个五角形圈的中心有1个由n个顶点和n条边 ...
- iOS 常用工具库LFKit功能介绍
简介:LFKit包含了平时常用的category,封装的常用组件,一些工具类. 需要LFKit中所有自定义控件的pod 'LFKit/Component' 需要LFKit中所有category的pod ...
- python多线程以及同步队列(转)
转自:http://www.w3cschool.cc/python/python-multithreading.html 多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长 ...
- winform WebBrowser如何修改使用默认的IE浏览器版本
在搜了一些相关资料原来WebBrowser使用的是IE的兼容模式进行浏览(IE7模式). 建议:先添加注册表中,然后使用注册表编辑器导出功能,产生reg注册文件:方便日后使用. Winform We ...
- delphi AlphaControls
http://blog.csdn.net/akof1314/article/details/7076804
- BootstrapValidator
一.引入必要文件 <link rel="stylesheet" href="/path/to/bootstrap/css/bootstrap.css"/& ...