我项目需要从服务器上接收图片(图片很多),我把它转成bitmap 类型显示,但我多接收几次就报内存溢出错误(每接收一次就清楚前面的图片),我现在时把这次的bitmap对象都放到list中,下载接收之前就循环把list中的bimap用recycle()方法清楚,可还是报内存溢出,各位大侠帮帮我
解决方案 »
- 第一次使用Eclipse开发Android软件,请看!
- 怎么用openGL播放视频啊
- 各位,如何让android自动挂载U盘
- 求解释,程序运行的时候莫名奇妙的退出了???
- 新建一个helloworl报错nullpointexception
- android Settings里的通话设置,帐户同步和辅助功能源码更改
- MediaPlayer同步播放问题
- Service的问题
- 请教,如何在android小游戏中加背景音乐,在需要显示音乐的类里怎么调。
- MotionEvent的getX()返回的数据单位是啥?像素?
- 在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语句。