__del__ not working with cyclic reference?
Aahz
aahz at pythoncraft.com
Wed Jul 2 00:04:02 EDT 2003
More information about the Python-list mailing list
Wed Jul 2 00:04:02 EDT 2003
- Previous message (by thread): whitespace and ?asc()?
- Next message (by thread): __del__ not working with cyclic reference?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): whitespace and ?asc()?
- Next message (by thread): __del__ not working with cyclic reference?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list