Why is this a mem leak?

jepler at unpythonic.net jepler at unpythonic.net
Fri Jul 23 05:00:06 CEST 2004

(The below message confuses Python, the language, with the CPython 2.3

In the absence of gc, l will never be collected. (well, "the thing l once
named", since it won't name anything directly after the "del" statement)

with cyclic GC plus refcounting, including Python 2.3 when built in the
default way, l will be collected.

"del l" has the effect of making the name "l" no longer refer to anything
and of decreasing the reference count of that object by 1.  It does not
relate directly to C's free() or C++'s delete, because those release
the storage underlying the object, even if pointers to that object still
exist elsewhere in the program.  CPython only releases the underlying
storage for the object when the refcount reaches 0, with "GC" being used
to find unreachable cycles and deal with them in some other way.


More information about the Python-list mailing list