__del__ not working with cyclic reference?
Aahz
aahz at pythoncraft.com
Wed Jul 2 00:04:02 EDT 2003
In article <ba1e306f.0307011837.269e3d2a at posting.google.com>,
Jane Austine <janeaustine50 at hotmail.com> wrote:
>
>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()
>--------
>
>Why is this so? Due to the cyclic reference? Isn't python's gc
>supposed to treat it? What singleton idiom is recommended
>otherwise?
There are two issues that you'll run into with this: gc doesn't work on
classes that define __del__(), and prior to Python 2.3, gc doesn't run
on exit.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Usenet is not a democracy. It is a weird cross between an anarchy and a
dictatorship.
More information about the Python-list
mailing list