"Help needed - I don't understand how Python manages memory"

"Martin v. Löwis" martin at v.loewis.de
Sun Apr 20 16:46:02 EDT 2008


> http://trac.edgewall.org/ contains at least one example of a reference
> leak. It's holding up the release of 0.11 for a while. *scnr*

All my investigations on possible memory leaks in Trac have only
confirmed that Python does _not_, I repeat, it does *NOT* leak any
memory in Trac.

Instead, what appears as a leak is an unfortunate side effect of
the typical malloc implementation which prevents malloc from returning
memory to the system. The memory hasn't leaked, and is indeed available
for further allocations by trac.

> The problem is also covered by the docs at
> http://docs.python.org/dev/library/sys.html#sys.exc_info

Ah, but that's not a *reference* leak. If Python (or an extension
module) contains a reference leak, that's a bug.

A reference leak is a leak where the reference counter is increased
without ever being decreased (i.e. without the application having
a chance to ever decrease it correctly). In this case, it's just a
cyclic reference, which will get released whenever the garbage
collector runs next, so it's not a memory leak.

Regards,
Martin



More information about the Python-list mailing list