Hi,

I'm looking at List8 in the sdk api samples folder. In this example,
the list adapter doesn't recycle 'convertView':

  public View getView(int position, View convertView, ViewGroup
parent) {
    // Make an ImageView to show a photo
    ImageView i = new ImageView(mContext);

    i.setImageResource(mPhotos.get(position));
    i.setAdjustViewBounds(true);
    i.setLayoutParams(new AbsListView.LayoutParams(
      LayoutParams.WRAP_CONTENT,
      LayoutParams.WRAP_CONTENT));
    // Give it a nice background
    i.setBackgroundResource(R.drawable.picture_frame);
    return i;
  }

I'm running this example on a nexus one. I am flinging the listview up
and down, and it seems to grow the heap up to 8mb at times before
releasing anything. This doesn't happen when convertView is recycled,
the memory usage remains quite stable as expected.

I started working on a project where there's an adapter implemented
which also does not recycle convertView. Same behavior as above, I can
grow the heap to 12/13mb before anything is released. So I end up
seeing a lot of out of memory exceptions as I play with other parts of
the app and so much memory is already allocated.

There's no reason not to use convertView, and none of this behavior is
unexpected. I thought though that in earlier versions of the SDK that
listview would internally release views more quickly if you weren't
using convertView, and were allocating all of them like in the above
example? By earlier versions, I mean like the first version of the SDK
two years ago, when we were trying to figure out what convertView was
at all. Just curious,

Thanks

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

Reply via email to