title: Explicitly freeing memory in c#
body: <p>I've create a c# application which uses up 150mb of memory (private bytes), mainly due to a big dictionary:</p>
  
  <pre><code>Dictionary&lt;string, int&gt; Txns = new Dictionary&lt;string, int&gt;();
  </code></pre>
  
  <p>I was wondering how to free this memory up. I've tried this:</p>
  
  <pre><code>Txns = null;
  GC.Collect();
  </code></pre>
  
  <p>But it doesn't seem to make much of a dent in my private bytes - they drop from say 155mb to 145mb.
  Any clues?</p>
  
  <p>Thanks</p>
  
  <p>-edit-</p>
  
  <p>Okay I'm having more luck with this code (it gets the private bytes down to 50mb), but why?</p>
  
  <pre><code>Txns.Clear(); // &lt;- makes all the difference
  Txns = null;
  GC.Collect();
  </code></pre>
  
  <p>-edit-</p>
  
  <p>Okay for everyone who says 'don't use GC.collect', fair enough (I'm not going to debate that, other than saying you can see my C background coming through), but it doesn't really answer my question:
  Why does the garbage collector only free the memory if i clear the transaction list first? Shouldn't it free the memory anyway, since the dictionary has been dereferenced?</p>