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 _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com