android中bitmap释放问题 我项目需要从服务器上接收图片(图片很多),我把它转成bitmap 类型显示,但我多接收几次就报内存溢出错误(每接收一次就清楚前面的图片),我现在时把这次的bitmap对象都放到list中,下载接收之前就循环把list中的bimap用recycle()方法清楚,可还是报内存溢出,各位大侠帮帮我 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 recycle 好像没什么效果,赋为null试吧bitmap 直接定义全局吧,不要每次都重新定义 song.setImage(getBitmapFromByte(image)); if(bitmap!=null&&bitmap.isRecycled()) { bitmap.recycle(); bitmap=null; //System.gc(); }//字节转换成Bitmappublic Bitmap getBitmapFromByte(byte[] temp){ if(temp != null){ bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length); return bitmap; }else{ return null; } } for(int i=0;i<200;i++){song.setImage(getBitmapFromByte(image)); if(bitmap!=null&&bitmap.isRecycled()) { bitmap.recycle(); bitmap=null; //System.gc(); }} 我碰到过内存溢出的问题,eclips也是报图片内存溢出,我最后查到是因为线程没结束,被开了多次就这样了,保证线程能退出,我的问题就解决了,不知道你是不是也是因为别的地方引起的 释放内存的代码有问题应该是if((bitmap!=null)&&(bitmap.isRecycled()==false)) { bitmap.recycle(); bitmap=null; }另外,Android给每个进程的堆大小为16MB,如果超过,就会报错 public Bitmap dealImage(byte[] imgByte){ Bitmap bitmap; float imagew = 240; float imageh = 180; BitmapFactory.Options bitmapFactoryOptions = new BitmapFactory.Options(); bitmapFactoryOptions.inJustDecodeBounds = true; bitmap = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length, bitmapFactoryOptions); int yRatio = (int)Math.ceil(bitmapFactoryOptions.outHeight/imageh); int xRatio = (int)Math.ceil(bitmapFactoryOptions.outWidth/imagew); if (yRatio > xRatio) { bitmapFactoryOptions.inSampleSize = yRatio; } else { bitmapFactoryOptions.inSampleSize = xRatio; } bitmapFactoryOptions.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length, bitmapFactoryOptions); return bitmap; } if(bitmap!=null&&bitmap.isRecycled()) { bitmap.recycle(); bitmap=null; //System.gc(); }这段有问题啊,bitmap.isRecycled())为true时候才执行recycle语句。 中兴V880不能实现网络定位的问题 安卓的前景怎么样啊? 请问如何在信号图标的旁边加入新图标? 怎么在Android模拟器的sd卡中,新建一个新的文件夹? android类似书翻页的activity跳转动画如何实现 【提问】如何才能把自定义的listview单独放进一个class文件 读取sd卡根目录下的视频 形成缩略图出错 跪求大神大牛们帮帮菜鸟小妹,急急急 如何实现手机浏览器功能 Android涂鸦性能 在AlertDialog中使用AutoCompleteTextView不成功,求助!! Android如何获取系统空闲时间
if(bitmap!=null&&bitmap.isRecycled())
{
bitmap.recycle();
bitmap=null;
//System.gc();
}
//字节转换成Bitmap
public Bitmap getBitmapFromByte(byte[] temp){
if(temp != null){
bitmap = BitmapFactory.decodeByteArray(temp, 0, temp.length);
return bitmap;
}else{
return null;
}
}
{
song.setImage(getBitmapFromByte(image));
if(bitmap!=null&&bitmap.isRecycled())
{
bitmap.recycle();
bitmap=null;
//System.gc();
}
}
应该是
if((bitmap!=null)&&(bitmap.isRecycled()==false))
{
bitmap.recycle();
bitmap=null;
}
另外,Android给每个进程的堆大小为16MB,如果超过,就会报错
Bitmap bitmap;
float imagew = 240;
float imageh = 180;
BitmapFactory.Options bitmapFactoryOptions = new BitmapFactory.Options();
bitmapFactoryOptions.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length, bitmapFactoryOptions);
int yRatio = (int)Math.ceil(bitmapFactoryOptions.outHeight/imageh);
int xRatio = (int)Math.ceil(bitmapFactoryOptions.outWidth/imagew);
if (yRatio > xRatio) {
bitmapFactoryOptions.inSampleSize = yRatio;
}
else {
bitmapFactoryOptions.inSampleSize = xRatio;
}
bitmapFactoryOptions.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length, bitmapFactoryOptions);
return bitmap;
}
{
bitmap.recycle();
bitmap=null;
//System.gc();
}
这段有问题啊,bitmap.isRecycled())为true时候才执行recycle语句。