title: Proper use of the IDisposable interface
body: <p>I know from reading <a href="https://docs.microsoft.com/dotnet/api/system.idisposable" rel="noreferrer">Microsoft documentation</a> that the &quot;primary&quot; use of the <code>IDisposable</code> interface is to clean up unmanaged resources.</p>
  <p>To me, &quot;unmanaged&quot; means things like database connections, sockets, window handles, etc.  But, I've seen code where the <code>Dispose()</code> method is implemented to free <em>managed</em> resources, which seems redundant to me, since the garbage collector should take care of that for you.</p>
  <p>For example:</p>
  <pre class="lang-cs prettyprint-override"><code>public class MyCollection : IDisposable
  {
      private List&lt;String&gt; _theList = new List&lt;String&gt;();
      private Dictionary&lt;String, Point&gt; _theDict = new Dictionary&lt;String, Point&gt;();
  
      // Die, clear it up! (free unmanaged resources)
      public void Dispose()
      {
          _theList.clear();
          _theDict.clear();
          _theList = null;
          _theDict = null;
      }
  }
  </code></pre>
  <p>My question is, does this make the garbage collector free memory used by <code>MyCollection</code> any faster than it normally would?</p>
  <hr />
  <p><strong>Edit</strong>:  So far people have posted some good examples of using <code>IDisposable</code> to clean up unmanaged resources such as database connections and bitmaps.  But suppose that <code>_theList</code> in the above code contained a million strings, and you wanted to free that memory <em>now</em>, rather than waiting for the garbage collector.  Would the above code accomplish that?</p>