Sunday, October 16, 2011

[android-developers] Re: listview adapter. Recycle bitmap

Based on the code there, you wouldn't have the chance to recycle the bitmap as you don't keep a handle to it anywhere.

Then again, if the ListView discards that particular row and you aren't retaining any handles to the bitmap, then the bitmap should be scheduled for collection by the GC. If you did try to retrieve the view that was holding the image from the ListView and it did return it to you, there is a good chance the ListView still wants to use it and you would not want to release the bitmap.

Is there a reason you are wanting to try to recycle the bitmap?

Also, we are talking about the recycle() function on bitmap and not reusing the same bitmap, correct?

Steven
Studio LFP
http://www.studio-lfp.com


On Sunday, October 16, 2011 4:14:48 AM UTC-5, emanuele wrote:
Hello guys.. that s my baseAdapter getview implmentation:

@Override
public View getView(int position, View convertView, ViewGroup parent)
{

int type = getItemViewType(position);
if (convertView == null) {
switch (type) {
case TYPE_BIG_NEWS:
convertView = mInflater.inflate(R.layout.big_news, null);
break;
case TYPE_NORMAL_NEWS:
convertView = mInflater.inflate(R.layout.normal_news, null);
break;
default:
break;
}
}

ImageView thumb = (ImageView)
convertView.findViewById(R.id.thumbId);




File f = null;
if (filename != null)
f = mFileCache.getFile(i.newsKey, filename);
if (f == null) {
if (mGetThumbsThread != null && filename != null) {
Log.i(TAG, "cache miss");
thumbLinks.offer(new ThumbRequest(i.newsKey, i.thumbLink,
i.thumbName));
mGetThumbsThread.signal();
}
thumb.setImageResource(placeHolder);
} else {
Log.i(TAG,
"file bitmap cached: " + f.getName() + " size: " + f.length() /
1024);
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
thumb.setImageBitmap(bitmap);
}

return convertView;
}


Every row is compound of text and an ImageView. Is there any chance to
recycle the bitmap I use in the getView?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment