On Mon, Oct 18, 2010 at 4:58 PM, John Gaby <jg...@gabysoft.com> wrote:
> I appear to have a memory leak(s) in my application, and I am trying
> to get a handle on it by trying to understand more about garbage
> collection.  I have created the following application.
>
> Here I have a class 'MyClass', and I create an instance of that class
> in my 'onCreate'.  I then null out the pointer which should leave no
> references to that instance.
>
> In 'MyClass', I override the finalize method so that I can see when
> the object is destroyed.  When I run this program, the finalize method
> is never called, even if I call System.gc(), from within my program,
> or use the 'Cause GC' button using DDMS.  (This is the same behavior
> that I see in my full application, by the way).
>
> Can someone explain to me more about what is going on here.  I believe
> that in my main application, that I have objects that are not being
> freed.  Is there some strategy for identifying those objects?
>
> Thanks.

Ok, few things first:
- Android does not reclaim the memory straight away even after the
application gets closed.
- System.gc() does not guarantee garbage collection in a timely manner.
- When overriding finalize() you have to call super.finalize().

The fact that you did not see the log from finalize() does not mean it
did not happen.

Daniel

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to