title: Python is not freeing memory
body: <p>I've been working with XML resources, and it seems that Python is issuing a weird behavior. I've tested both <code>lxml</code> library and <code>xml.etree.ElementTree</code>, both holding memory after it should be collected by <code>gc</code>. I typed <code>gc.collect()</code> as a test, but nothing else happen: memory still being held by process.</p>
  
  <p>Imports:</p>
  
  <pre><code>import time
  from lxml import etree
  import gc
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>def process_alternative():
      """
      This alternative process will use lxml
      """
      filename = u"/tmp/randomness.xml"
      fd = open(filename, 'r')
      tree = etree.parse(fd)
      root = tree.getroot()
  
      accum = {}
  
      for _item in root.iter("*"):
          for _field in _item.iter("*"):
              if _field.tag in accum.keys():
                  accum[_field.tag] += 1
              else:
                  accum[_field.tag] = 1
  
      for key in accum.keys():
          print "%s -&gt; %i" % (key, accum[key])
  
      fd.close()
      gc.collect()
  </code></pre>
  
  <p>And this is my main</p>
  
  <pre><code>if __name__ == "__main__":
      while True:
          print "Wake up!"
          process_alternative()
          print "Sleeping..."
          time.sleep(30)
  </code></pre>
  
  <p>As you see, this main calls "process_alternative", and then sleep. XML file provided loads memory with nearly 800MB; so, before <code>time.sleep</code>, memory should be freed by process, returning to basic VM memory needed (around 32MB?). Instead, process continue holding around 800MB.</p>
  
  <p>Any tip about why memory has not been freed after every iteration?</p>
  
  <p>Using ubuntu 13.04, Python 2.7.4</p>
  
  <p>This function deallocates memory in every iteration</p>
  
  <pre><code>def check_memory():
      ac1 = [a1**5 for a1 in xrange(10000000)]
      time.sleep(5)
      ac2 = [a1**5 for a1 in xrange(10000000)]
      time.sleep(5)
      ac3 = [a1**5 for a1 in xrange(10000000)]
  </code></pre>