title: In c# how to know if a weak referenced object is going to be garbage collected?
body: <p>Suppose I have such code:</p>
  
  <pre><code>class Test
  {
      WeakReference m_ref;
  
      public Test()
      {
          Test1();
          Test2();
      }
  
      void Test1()
      {
          m_ref = new WeakReference(new object());
      }
  
      void Test2()
      {
          // If I do the GC then the m_ref.Target is null
          // GC.Collect();
          Debug.Log(m_ref.Target);
      }
  }
  
  void TestFunc()
  {
      new Test();
  }
  </code></pre>
  
  <p>In this example I created a new object instance and set it to a <code>WeakReference</code> instance in <code>Test1</code>. If I understand correctly after exit the <code>Test1</code> there would be nothing referenced to the object instance so this instance would be <code>GC</code> soon.</p>
  
  <p>However, in the <code>Test2</code> if <code>GC</code> is not performed I can still access the object instance via <code>m_ref.Target</code>.</p>
  
  <p>Is there any way I could know that the <code>m_ref.Target</code> is invalid <strong>without</strong> manually perform the <code>GC</code>?</p>