title: Releasing memory in Python
body: <p>I have a few related questions regarding memory usage in the following example.</p>
  
  <ol>
  <li><p>If I run in the interpreter,</p>
  
  <pre><code>foo = ['bar' for _ in xrange(10000000)]
  </code></pre>
  
  <p>the real memory used on my machine goes up to <code>80.9mb</code>. I then,</p>
  
  <pre><code>del foo
  </code></pre>
  
  <p>real memory goes down, but only to <code>30.4mb</code>. The interpreter uses <code>4.4mb</code> baseline so what is the advantage in not releasing <code>26mb</code> of memory to the OS? Is it because Python is "planning ahead", thinking that you may use that much memory again?</p></li>
  <li><p>Why does it release <code>50.5mb</code> in particular - what is the amount that is released based on?</p></li>
  <li><p>Is there a way to force Python to release all the memory that was used (if you know you won't be using that much memory again)?</p></li>
  </ol>
  
  <p><strong>NOTE</strong>
  This question is different from <a href="https://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python">How can I explicitly free memory in Python?</a>
  because this question primarily deals with the increase of memory usage from baseline even after the interpreter has freed objects via garbage collection (with use of <code>gc.collect</code> or not).</p>