John,

I've seen something similar causing memory leaks, preventing GC from working, although not in Android:

public class Item {
static HashtablegHash = new Hashtable();

private String key;

public Item(String key) {
this.key = key;
gHash.put(key, this);
}

public void finalize() {
gHash.remove(this.key);
}
}

In your example, there is a circular reference, but the entire object is orphaned. GC should work here, so there must be more to it.

I'd recommend you try switching to a separate class for the adapter. Making it an non-static inner class of GListView would be quite convenient.

-- Kostya

20.10.2010 8:53, John Gaby пишет:
I have a class 'GListView' which extends ListView and acts as it's own
adapter.  It is declared thus:

public class GListView extends ListView implements ListAdapter

In it's constructor, I set it's adapter to itself as follows:

public GListView(Context context ...)
{
...

     setAdapter(this);

...
}

I then add this GListView to a ViewGroup.  Later I release all
references to the ViewGroup, and yet the ViewGroup and the GListView
are never garbage collected.

Now if I don't do the 'setAdapter(this)' call, everything the garbage
collection works as expected, so it seems that setting the adapter to
itself is creating some kind of circular references that the garbage
collector is not able to sort out

I have tried calling setAdapter(null) when I no longer need the view,
but that does not seem to help.

Is having my GListView act as it's own ListAdapter something I simply
cannot do, or is there some way to make this work?

Thanks.



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
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