Not using setTag() right, seems to block gc?
<p>I'm using the view holder pattern with my ListView. When I run my app for some time, I see that I have lots of ViewHolder instances retained:</p>

<pre><code>@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.foo, null);

        holder = new ViewHolder();
        holder.username = (TextView) convertView.findViewById(R.id.username);
        holder.address = (TextView) convertView.findViewById(R.id.address);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }

    ...

    return convertView;
}

private static class ViewHolder {
    TextView username;
    TextView address;
}
</code></pre>

<p>I'm using the UI monkey tool to run batches of 5,000 random operations. The first run, I see about 6 ViewHolder instances in memory. Then about 10, then 15, and so on. I'm seeing these through the memory analyzer tool.</p>

<p>I'm not sure why these additional instances are not being cleaned up. Each ViewHolder instance is retaining "mTag", which then has a large tree under it (the entire view).</p>

<p>Has anyone else seen this?</p>

<p>------------------ Update -------------------------</p>

<p>Still haven't had any luck finding out what's going on. In the Memory Analyzer Tool, I see references I don't understand to the view holder instances (there are currently about 21 instances, while my screen can only fit about 6 at any given time). With the incoming references shown, they look something like this:</p>

<pre><code>com.me.project.MyAdapter$ViewHolder
   |-- mTag
   |     |-- mParent (TextView)
   |     |-- mParent (TextView)
   |     |-- [1] java.lang.Object[12]
   |          |-- array (mCurrentScrap android.widget.AbsListView$RecycleBin)
   |
com.me.project.MyAdapter$ViewHolder
   |-- mTag (this one looks ok, only lists the two TextView references)
   |
com.me.project.MyAdapter$ViewHolder
   |-- mTag .. 
   |-- [1] android.view.View[12]
        |-- mChildren android.widget.ListView
            |-- this$0 android.widget.ListView$FocusSelector
            |-- this$0 android.widget.AdapterView$AdapterDataSetObserver
            ...
</code></pre>

<p>So some instances have only connections to the member variables of ViewHolder (makes sense), others have connections to other data that seems to be part of the parent ListView, but not related to the ViewHolder itself. These don't seem to be getting cleaned up though, and after some time I'll have dozens of these hanging around.</p>

<p>Just to be clear, out of the 20 or so instances I currently had in my most recent mem snapshot, I'll have more than one instance looking like each of those parent nodes above (so multiple instances have the ListView$FocusSelector child under it, etc).</p>

<p>Thanks</p>
