Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.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: Tue, 24 Feb 2015 18:20:29 +1300 Lines: 12 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 1VTiCadHg6jCNmCLYB4vHQt1Cxz9ply2EHE+5+692/TkI+nOlX Cancel-Lock: sha1:Cv4Jc1A869q1D/WkqDW1lxwZj3A= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:86293 Cem Karan wrote: > I tend to structure my code as a tree or DAG of objects. The owner refers to > the owned object, but the owned object has no reference to its owner. With > callbacks, you get cycles, where the owned owns the owner. 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. -- Greg