Design thought for callbacks

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Feb 24 16:19:18 EST 2015


random832 at fastmail.us wrote:
> On Tue, Feb 24, 2015, at 00:20, Gregory Ewing wrote:
> 
>>This is why I suggested registering a listener object
>>plus a method name instead of a callback. It avoids that
>>reference cycle, because there is no long-lived callback
>>object keeping a reference to the listener.
> 
> How does that help? Everywhere you would have had a reference to the
> "callback object", you now have a reference to the listener object.

The point is that the library can keep a weak reference
to the listener object, whereas it can't reliably keep
a weak reference to a bound method.

-- 
Greg



More information about the Python-list mailing list