[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Finalization

From: Rhys Weatherley
Subject: Re: [DotGNU]Finalization
Date: Sun, 22 Jun 2003 20:03:40 +1000
User-agent: KMail/1.4.3

On Sunday 22 June 2003 07:52 pm, Thong \(Tum\) Nguyen wrote:

>         public static void Main()
>         {
>                 new Pok();
>                 new Pok();
>                 new Pok();
>                 GC.Collect();
>                 GC.WaitForPendingFinalizers();
>         }
> }
> It should print out "finalized!" thrice but it only prints it out once.
> It looks like the first (and only the first) finalizable object is never
> finalized.

It's possible that the pointer to one of the objects is still stored somewhere 
in the stack when the GC run happens.  It will get picked up as "still in 
use" by the conservative collector.  It will only get collected if the 
pointer is overwritten somehow.

Because there are three calls to "new Pok()", the second and third will 
overwrite the temporary storage used by the first and second.  This will 
leave a pointer to the third still in play, and hence uncollectable until 
something else stomps on it.

Welcome to the wonderful world of conservative garbage collection. :-)

We probably can't do anything about this for explict calls to the collector, 
but we may be able to do something for the shutdown run in 

Prior to calling the collector for the last time, clear all of the CVM thread 
stacks to zero.  This will remove any transistory pointers and allow them to 
be collected.  Some experimentation is probably required to find the right 
balance - I doubt you'll be able to collect everything.

> PS.  I have monitors working and finalizers are now running on a
> separate thread :D.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]