title: How to diagnose potential memory leak in Python program?
body: <p>I have an embedded Linux system with 256MB of RAM.  There is a large codebase running on it, most in C++ but some utilities are in Python.  We have a Python "package manager" that handles updates to the system using the <a href="http://apt.alioth.debian.org/python-apt-doc/" rel="nofollow">Python apt module</a> (we distribute our updates as .deb files).  When running, this application uses a large portion of the system RAM.  I am monitoring RAM usage with top, looking at the RSS for the Python process (maybe this is not a valid way to analyze process memory usage?  Open to suggestions).</p>
  
  <p>The line</p>
  
  <pre>
      cache = apt.Cache() 
  </pre>
  
  <p>which is called periodically to check on the status of the system seems to consume about 20MB each time it is called, and it doesn't look like this memory is being returned.  I tried deleting the cache object at the end of the function and running gc.collect(), that didn't seem to help much.</p>
  
  <p>How can I reduce the memory usage of this program?</p>
  
  <p>The platform is ARM Cortex A8, running Linux 3.2, Debian Wheezy and Python 2.7.3. </p>