Thanks for the input.  I am a little confused about your comment:

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

Are you saying that the finalize can be called and yet I may not get
the log?  How is that possible?

I added the call to super.finalize() as you suggested (it didn't
change anything), but please note that I really don't care about the
finalize being called, except as a debugging tool.  What I really want
is a way to find out whether an object has been freed (or will be
freed) or not.  I believe that I must have objects that are not being
freed, and I would like to try and identify them.

Thanks



On Oct 18, 9:26 am, Daniel Drozdzewski <daniel.drozdzew...@gmail.com>
wrote:
> 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