Let's say I have the following class:
public class Immortal
{
private static System.Collections.ArrayList immortals = new System.Collections.ArrayList();
public Immortal()
{
}
~Immortal()
{
// rise from your grave!
immortals.Add(this);
System.Gc.ReRegisterForFinalize(this);
}
}
If I then do the following:
Immortal being = new Immortal();
being = null;
System.GC.WaitForPendingFinalizers();
Will the program hang waiting for an immortal object to die?
I know that the docs don't guarantee that WaitForPendingFinalizers will ever return, but I'm just curious if this will hang it.