Why is a WeakReference useless in a destructor?
<p>Consider the following code:</p>

<pre><code>class Program
{
    static void Main(string[] args)
    {
        A a = new A();
        CreateB(a);

        GC.Collect();
        GC.WaitForPendingFinalizers();
        Console.WriteLine("And here's:" + a);
        GC.KeepAlive(a);
    }

    private static void CreateB(A a)
    {
        B b = new B(a);
    }
}

class A
{ }

class B
{
    private WeakReference a;
    public B(A a)
    {
        this.a = new WeakReference(a);
    }

    ~B()
    {
        Console.WriteLine("a.IsAlive: " + a.IsAlive);
        Console.WriteLine("a.Target: " + a.Target);
    }
}
</code></pre>

<p>With the following output:</p>

<pre><code>a.IsAlive: False
a.Target:
And here's:ConsoleApp.A
</code></pre>

<p>Why is it false and null? A hasn't been collected yet.</p>

<p><strong>EDIT</strong>: Oh ye of little faith.</p>

<p>I added the following lines:</p>

<pre><code>Console.WriteLine("And here's:" + a);
GC.KeepAlive(a);
</code></pre>

<p>See the updated output.</p>
