__del__ not working with cyclic reference?
Peter Abel
p-abel at t-online.de
Wed Jul 2 01:35:08 EDT 2003
janeaustine50 at hotmail.com (Jane Austine) wrote in message news:<ba1e306f.0307011837.269e3d2a at posting.google.com>...
> 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()
Doen't understand what you're doing here.
For me you define a classvariable named **foobar**
which is bound to an instance of class **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?
>
For me the following works:
>>> class FooBar:
... def __del__(self):
... print "FooBar removed"
...
>>> foo=FooBar()
>>> del foo
FooBar removed
>>>
> Thanks
>
> Jane
Regards
Peter
More information about the Python-list
mailing list