我项目需要从服务器上接收图片(图片很多),我把它转成bitmap 类型显示,但我多接收几次就报内存溢出错误(每接收一次就清楚前面的图片),我现在时把这次的bitmap对象都放到list中,下载接收之前就循环把list中的bimap用recycle()方法清楚,可还是报内存溢出,各位大侠帮帮我

解决方案 »

  1.   

    recycle 好像没什么效果,赋为null试吧bitmap 直接定义全局吧,不要每次都重新定义
      

  2.   

    song.setImage(getBitmapFromByte(image));
         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; 
       }
      }
      

  3.   

    for(int i=0;i<200;i++)
    {
    song.setImage(getBitmapFromByte(image));
             if(bitmap!=null&&bitmap.isRecycled())
             {
              bitmap.recycle();
     bitmap=null;
     //System.gc();
             }
    }
      

  4.   

    我碰到过内存溢出的问题,eclips也是报图片内存溢出,我最后查到是因为线程没结束,被开了多次就这样了,保证线程能退出,我的问题就解决了,不知道你是不是也是因为别的地方引起的
      

  5.   

    释放内存的代码有问题
    应该是
    if((bitmap!=null)&&(bitmap.isRecycled()==false))
      {
       bitmap.recycle();
       bitmap=null;
      }
    另外,Android给每个进程的堆大小为16MB,如果超过,就会报错
      

  6.   

    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;
     
    }
      

  7.   

    if(bitmap!=null&&bitmap.isRecycled())
       {
       bitmap.recycle();
     bitmap=null;
     //System.gc();
       }
    这段有问题啊,bitmap.isRecycled())为true时候才执行recycle语句。