Why this ref leak?

Thomas Heller theller at ctypes.org
Wed Feb 27 08:12:06 EST 2008


Gerhard Häring schrieb:
> import sys
> 
> def foo():
>      class C(object):
>          pass
> 
> foo()
> print ">>", sys.gettotalrefcount()
> foo()
> print ">>", sys.gettotalrefcount()
> foo()
> print ">>", sys.gettotalrefcount()
> 
>  >> 21366
>  >> 21387
>  >> 21408
> [9779 refs]
> 
> Both Python 2.4 and 2.5 don't clean up properly here. Why is this? 
> Aren't classes supposed to be garbage-collected?
> 
> -- Gerhard

Replace "foo()" with "foo(); gc.collect()" and the refcounts are stable.
Tested the python 2.6 from trunk.

Thomas




More information about the Python-list mailing list