title: Garbage Collection should have removed object but WeakReference.IsAlive still returning true
body: <p>I have a test that I expected to pass but the behavior of the Garbage Collector is not as I presumed:</p>
  
  <pre><code>[Test]
  public void WeakReferenceTest2()
  {
      var obj = new object();
      var wRef = new WeakReference(obj);
  
      wRef.IsAlive.Should().BeTrue(); //passes
  
      GC.Collect();
  
      wRef.IsAlive.Should().BeTrue(); //passes
  
      obj = null;
  
      GC.Collect();
  
      wRef.IsAlive.Should().BeFalse(); //fails
  }
  </code></pre>
  
  <p>In this example the <code>obj</code> object should be GC'd and therefore I would expect the <code>WeakReference.IsAlive</code> property to return <code>false</code>.</p>
  
  <p>It seems that because the <code>obj</code> variable was declared in the same scope as the <code>GC.Collect</code> it is not being collected. If I move the obj declaration and initialization outside of the  method the test passes.</p>
  
  <p>Does anyone have any technical reference documentation or explanation for this behavior?</p>