__del__ not working with cyclic reference?

Jane Austine janeaustine50 at hotmail.com
Tue Jul 1 22:37:50 EDT 2003


I have some code using singleton pattern. The singleton instance
is shared as a class variable. The problem is that the singleton
instance is not cleared automatically.

Following is a simplified version that shows the problem:

--------
#foobar.py
class FooBar:
    def __del__(self):
        print "FooBar removed"

FooBar.foobar=FooBar()
--------

c:\python23>python foobar.py

c:\python23>

It doesn't print anything.

Why is this so? Due to the cyclic reference? Isn't python's gc
supposed to treat it? What singleton idiom is recommended 
otherwise?

Thanks

Jane




More information about the Python-list mailing list