Leakage vs Cyclops

Martin v. Löwis martin at v.loewis.de
Fri Jan 3 19:43:07 EST 2003


Robin Becker <robin at jessikat.fsnet.co.uk> writes:

> this leak is present with 1.52 so it's not a function of 2.2/gc. Are you
> saying there are cycles/leaks that are not caught by inspecting toplevel
> module variables?

"There are" is a big general here. It is certainly possible to have
such leaks; a simple error in INCREF/DECREF could easily trigger such
problems. Of course, the Python core never should have such leaks, and
likely has none that have survived since 1.5.2.

However, there are other causes of memory consumption, too, for
example lists that grow longer and longer without ever being part of a
cycle.

The most notable such thing is the dictionary of interned strings,
which isn't even reachable through a module level variable. This is by
design; this design will change only in Python 2.3 (where interned
strings become mortal).

If you meant "toplevel module" literally, then there are certainly way
more things unreachable: unless sys is imported, you won't find
sys.modules from the toplevel module. 

Even if you add sys.modules to your object roots, there are still
unreachable non-garbage objects: C modules may hold them in global
variables, and not expose them. There are many such cases in Python
1.5.2, and still a lot in newer versions (although more and more
objects get exposed in more recent releases).

Regards,
Martin





More information about the Python-list mailing list