title: Does garbage collector call Dispose()?
body: <p>I thought the GC would call Dispose eventually if your program did not but that you should call Dispose() in your program just to make the cleanup deterministic.</p>
  
  <p>However, from my little test program, I don't see Dispose getting called at all....</p>
  
  <pre><code>public class Test : IDisposable
  {
      static void Main(string[] args)
      {
          Test s = new Test();
          s = null;
          GC.Collect();
          Console.ReadLine();
      }
  
      public Test()
      {
          Console.WriteLine("Constructor");
      }
  
      public void Dispose()
      {
          Console.WriteLine("Dispose");
      }
  }
  </code></pre>
  
  <p>// Output is just "Constructor", I don't get "Dispose" as I would expect.  What's up?</p>
  
  <p><strong>EDIT:</strong> Yes, I know I should call Dispose() - I do follow the standard pattern when using disposable objects.  My question arises because I'm trying to track down a leak in somebody elses code, which is managed C++ (another layer of complexity that would be the good subject of another thread).</p>