Understanding memory leak reports

kyosohma at gmail.com kyosohma at gmail.com
Fri Dec 21 14:10:22 EST 2007


On Dec 21, 12:44 pm, "Giampaolo Rodola'" <gne... at gmail.com> wrote:
> Hi,
> I'm in a big trouble since I don't know how to find some memory leaks
> I just discovered in a program of mine.
> By putting:
>
> import gc
> gc.set_debug(gc.DEBUG_LEAK)
>
> ..at the end of a script which imports a module I wrote it seems I
> have some memory leaks scattered around.
> The message printed on screen is the following:
>
> gc: collectable <function 00C70E70>
> gc: collectable <type 00B41018>
> gc: collectable <dict 00C6DE40>
> gc: collectable <tuple 00C09900>
> gc: collectable <tuple 00BCD510>
> gc: collectable <function 00C70EB0>
> gc: collectable <function 00C70E30>
>
> Since the main module is very big (more than 2800 lines of code) I do
> not understand which objects are not garbage collected.
> Is there a way to have a more detailed message to know which objects
> are not garbage collected?
> For example "function foo", "method MyClass.bar", "dict my_dict"...
> "function 00C70E70" and "tuple 00C09900" are too much generic messages
> which don't give me an idea about where the leak could be.

I've never done this before, but here's what I found while Googling:

Recipe that supposedly gives more info:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65333

Another thread on the same topic that looks quite detailed:
http://www.thescripts.com/forum/thread22097.html

An article or two on memory leaks in Python:
http://utcc.utoronto.ca/~cks/space/blog/python/DebuggingPythonMemoryLeaks
http://www.nightmare.com/medusa/memory-leaks.html

I hope they help.

Mike



More information about the Python-list mailing list