[Python-3000] PEP: Eliminate del (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri May 4 06:08:59 CEST 2007


Giovanni Bajo wrote:

On 01/05/2007 18.09, Phillip J. Eby wrote: > That means that if 'self' in your example above is collected, then > the weakref no longer exists, so the closedown won't be called.

Yes, but as far as I understand it, the GC does special care to ensure that the callback of a weakref that is not part of a cyclic trash being collected is always called.

It has nothing to do with cyclic GC. The point is that if the refcount of a weak reference drops to zero before that of the object being weakly referenced, the weak reference object itself is deallocated and its callback is not called. So having the resource-using object hold the weak ref to the resource doesn't work -- it has to be kept in some kind of separate registry.

-- Greg



More information about the Python-3000 mailing list