如何从android Gallery :: GetView方法回收位图

时间:2011-02-17 11:37:59

标签: android garbage-collection gallery

在图库的getView方法中, 我下载了位图并设置为Imageview并将其返回到框架。 我何时何地回收位图? 我不想唤醒系统垃圾收集器来清理位图。

public View getView(int position, View view, ViewGroup parent) {
        ImageView i = new ImageView(mContext); 
        downloadFromWeb("www.blahblah.com", i);
        i.setScaleType(ImageView.ScaleType.FIT_XY);
        i.setLayoutParams(new Gallery.LayoutParams(mDisplayWidth, (mDisplayHeight-100)));
        i.setBackgroundResource(mGalleryItemBackground);
        return i;
    }

public downloadFromWeb(URL url, ImageView i){
        Bitmap bitmap = getBitmapFromWeb(url);
        i.setImageBitmap(bitmap);
  }

1 个答案:

答案 0 :(得分:0)

    You can call bitmap recycle method in onDestory method as shown below

Bitmap mybitmap= null;

@Override
    protected void onDestroy() {
        super.onDestroy();

        if(bm!=null)
        mybitmap.recycle();

    }