Destructor never called ???

Alex Martelli aleax at aleax.it
Fri Sep 20 11:05:35 EDT 2002


Aahz wrote:

> In article <buzi9.136158$pX1.4848554 at news2.tin.it>,
> Alex Martelli  <aleax at aleax.it> wrote:
>>Aahz wrote:
>>>
>>> There are several different issues.  First of all, __del__ does not get
>>> called if an object is destroyed by GC (GC gets used to clean up cyclic
>>> garbage).  Secondly, Jython does not use refcounting; it's pure GC, just
>>
>>Right, but, I'd put it differently: GC is inhibited from destroying
>>objects whose types define a __del__ -- rather, it collects them into
>>gc.garbage, because it can't know that finalizing them is safe.
> 
> Thanks (and also to Tim) for correcting my sloppy writing.

Reading Tim's post reminded me that _my own_ expression was quite
imperfect too  -- GC doesn't destroy objects *that are part of the
loop* and have a __del__... it DOES destroy object that have a
__del__ if they're not part of the loop itself, but rather, are
kept alive only by being referenced from objects in the loop, if
and when the loop itself is collected/destroyed.  Phew...


Alex




More information about the Python-list mailing list