using System;
using System.Runtime.InteropServices;
class Program
{
GCHandle handle;
Program()
{
handle = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection);
}
~Program()
{
Console.WriteLine(handle.Target != null);
}
static void Main()
{
new Program();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
Judging from the comments, many people had trouble understanding the previous code snippet. The above code is equivalent (except that this actually works on .NET 2.0). Maybe this will help clarify.