No destructor
Martin von Loewis
loewis at informatik.hu-berlin.de
Wed Aug 23 09:59:01 EDT 2000
"Pete Shinners" <pete at visionart.com> writes:
> because of this i've never been able to let myself rely on
> the __del__ destructor. (will it be called???) will the new
> garbage cleanup in 2.0 fix this problem?
If __del__ was not called because the object was part of a cycle, then
it still is garbage in 2.0; if an object in an cycle has an __del__,
the cycle won't be collected. IOW,
class X:
def __del__(self):
print self
x=X()
x.next=x
x=None
will still produce garbage in Python 2.
If the __del__ was not called because the object was referred-to by a
cycle, and the cycle is collectable, then __del__ will be called:
x=[]
x.append(x) # produce cycle
x.append(X()) # add reference to X instance
x=None
will release the list and the X instance.
Regards,
Martin
More information about the Python-list
mailing list