dotgnu-general
[Top][All Lists]
Advanced

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

RE: [DotGNU]Finalization


From: Thong \(Tum\) Nguyen
Subject: RE: [DotGNU]Finalization
Date: Sun, 22 Jun 2003 21:52:23 +1200

Ahh that makes sense.  I've got another problem though...

Check out this code:

using System;

public class TestFinalizer
{
        public class Pok
        {
                ~Pok()
                {
                        Console.WriteLine("finalized!");
                }
        }

        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.

I can't trace down the problem.  

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

Thanks,

^Tum


> -----Original Message-----
> From: Rhys Weatherley [mailto:address@hidden
> Sent: Sunday, 22 June 2003 12:50 p.m.
> To: Thong (Tum) Nguyen; address@hidden
> Subject: Re: [DotGNU]Finalization
> 
> On Sunday 22 June 2003 10:28 am, Thong \(Tum\) Nguyen wrote:
> 
> > It should print out "finalized!".
> 
> Actually, it is doing the right thing for "WaitForPendingFinalizers".
If you
> put "GC.Collect" just before the "WaitForPendingFinalizers" call, then
it
> will print things.
> 
> I tried it out on MS'es engine and the "WaitForPendingFinalizers"
didn't do
> anything either (because the GC hadn't run yet).  But once the engine
shut
> down, it printed the messages.
> 
> The problem is that we weren't running a final GC pass during engine
shutdown
> to run the remaining finalizers.  I just added this to
"ILExecProcessDestroy"
> and it seems to work now.  However, it will probably need adjusting
once
> threads are added to the system to properly shutdown the finalizer
thread.
> 
> Cheers,
> 
> Rhys.
> 
> _______________________________________________
> Developers mailing list
> address@hidden
> http://dotgnu.org/mailman/listinfo/developers




reply via email to

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