Can someone explain this weakref behavior?

Mike C. Fletcher mcfletch at
Mon Jun 14 17:55:20 CEST 2004

Michael Kent wrote:

>"Tim Peters" < at> wrote in message news:<mailman.874.1086976586.6949.python-list at>...
>>The bound methods you create become unreachable (via any strong reference)
>>the instant they're added to the weak dict, so they vanish from the weak
>>dict immediately after being added.  That's what a weak dict is supposed to
>OK, I think I understand where you're coming from.  My
>misunderstanding was that a persistant reference to the object would
>keep the object alive, and thus was sufficient to keep a weak
>reference to a bound method of the object alive.  But the two
>references are totally independent, right?  So keeping the object
>alive isn't sufficient to keeping the weak reference to a bound method
>of the object alive.
>Back to the drawing board...
Or you could just take the "saferef" module from the Dispatcher project 
(the poor naming is my fault):

Which does the work of deconstructing the method reference into two 
weak-references for you.  Once you have that, keeping the object alive 
is sufficient.


  Mike C. Fletcher
  Designer, VR Plumber, Coder

More information about the Python-list mailing list