Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Design thought for callbacks Date: Wed, 25 Feb 2015 10:19:18 +1300 Lines: 17 Message-ID: References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net bhtHMKtpIerLYpFU0Ei25ggYTkglBfw0un/a3M5X3e6HXVDMfu Cancel-Lock: sha1:7/zcl3Gn1QdRw4Kvwdw7Y01tgCY= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:86344 random832@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