python memory analysis

Jeremy Bowers jerf at
Mon Sep 6 17:38:28 CEST 2004

On Mon, 06 Sep 2004 16:51:09 +0200, Alexander Hoffmann wrote:
> You probably mean to utilize gc.get_objects and build some kind of statics 
> upon it, don't you ? 
> Ok, so this means there is indeed no tool which will help me with that ?  :-(
> -alex

So far, every time I've had a memory leak in Python, simply running the
process until it leaks for a while, then looking at gc.get_objects(), has
made it immediately clear what was being leaked. (Regretfully, I have
never been able to isolate a test case for any of these leaks.) You
usually see a bajillion instances of some class and that has always been
enough of a clue.

Due to how Python works, I'm not sure it is even possible to create a tool
that does any better than that. It is meaningful to talk about a C
function that "leaks memory" by allocating and never deallocating, but it
is much trickier to assign "blame" in Python in a way that could ever have
meaning to a tool. If the object is left lying around it is already
because the computer believes somebody has a reference to it; how is the
computer to "know" this reference isn't "real"? (Assuming no bugs in
Python of course, but even so you're left with the same problem.)

More information about the Python-list mailing list