In getView method of gallery , i had download the bitmap and set to Imageview and return it back to framework. When and where should i recycle the bitmap ? I don't want to wake up the system garbage collector to clean up the bitmaps.
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);
}
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();
}
精彩评论