memory leak troubleshooting techniques

Christoph Becker-Freyseng webmaster at beyond-thoughts.com
Tue Jul 29 18:20:28 EDT 2003


Adam Deutsch wrote:
> I would like to ask some advice about tracking down memory leaks in Python
> code.
> 
> We have a python application running on Python 2.0.1 in an embedded Linux
> environment (kernel version 2.4.7).  We have recently detected a memory leak
> that we can see from "ps aux" is attributable to the Python processes.
> Running Sam Rushing's (http://www.nightmare.com/medusa/memory-leaks.html)
> get_refcounts() function does not yield any smoking guns:  the reference
> counts for all classes remain stable even as memory use climbs.
> 
> Is there any systematic method of determining how Python is using its
> allocated memory?
> 
> Thanks.
> 
There might be one more readon for a memory-leak -- besides an 
increasing refcount.

Have you thought about a growing string? (or an similar object)
In Python a string can have 80 MB without problems / not "hurting" python.
Of course the refount won't get higher as there's just one string -- but 
this one might be getting *huge*.
I had such a problem when programming PersistentThreads. Making internal 
calls to the "ZopeRequestDispatcher" caused sys.path to grow.

Unfortunately I don't know a way in Python to list objects that consume 
more than xy bytes of memory.


Christoph Becker-Freyseng







More information about the Python-list mailing list