GC and finalizers [was: No destructor]

Martin von Loewis loewis at informatik.hu-berlin.de
Mon Aug 28 10:05:34 EDT 2000


nascheme at enme.ucalgary.ca (Neil Schemenauer) writes:

> Paul Duffin <pduffin at hursley.ibm.com> wrote:
> >What happens if after calling the finalizer on an object which has
> >a zero reference count the object has a non-zero reference count ?
> 
> The same thing that happens in Python without GC.  The object
> remains alive but the finalizer will not be called again (at
> least in 2.0).

Are you sure?

ython 2.0b1 (#4, Aug 25 2000, 17:14:42)  [GCC 2.95.2 19991024 (release)] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>>> import gc
>>> class X:
...   def __del__(self):
...     print "final"
...     global a
...     a=self
... 
>>> a=X()
>>> del a
final
>>> del a
final
>>> del a
final

Interestingly enough, if gc is not imported, behaviour is different...

Regards,
Martin



More information about the Python-list mailing list