[Python-Dev] Re: weakref gc semantics

Jim Fulton jim at zope.com
Fri Nov 5 15:25:20 CET 2004

Greg Ewing wrote:
> Neil Schemenauer wrote:
>> I think there may be one small problem though.  Callbacks get passed
>> the weakref object.  Doesn't that break the rule that trash should
>> not be exposed to Python code while the collection is taking place?
> Maybe the callback shouldn't be passed the weakref object?
> I don't see what good that does anyway, since the weakref
> is just an empty shell by then, isn't it?

No.  It can still be used as a key. It still has it's original
hash value and will compare equal to other weakrefs to the same
original object. Weak-key dictionaries depend on this. In addition,
as Tim points out, it could be a weakref-subclass instance and
could have additional useful data.


Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org

More information about the Python-Dev mailing list