Python leaks in cyclic garbage collection

Andrea Crotti andrea.crotti.0 at
Sat Feb 19 03:40:33 EST 2011

Il giorno 19/feb/2011, alle ore 05.10, moerchendiser2k3 ha scritto:

> Hi, I have some problems with Python and the garbage collection. In
> the following piece of code I create a simple gargabe collection but I
> am still wondering why the finalizers are never called - at least on
> exit of Py they should be called somehow. What do I miss here? I know,
> there is no deterministic way how to resolve this though.
> class Foo():
>    def __init__(self):
>        self.b=Bar(self)
>    def __del__(self):
>        print "Free Foo"
> class Bar():
>    def __init__(self, f):
>        self.f=f
>    def __del__(self):
>        print "Free Bar"
> f=Foo()
> print f
> -- 

Wild guess:
maybe when python exits they are called but sys.stdout has already been closed and nothing gets written on it anymore.

More information about the Python-list mailing list