AST structures and memory leaks

Robin Becker robin at jessikat.demon.co.uk
Thu Mar 16 09:45:28 EST 2000


In message <1258906958-9249420 at hypernet.com>, Gordon McMillan
<gmcm at hypernet.com> writes
>Robin Becker wrote:
>
>
....
>> Is there any way to find the 'owner' of an instance?
>
>The general case would probably be:
>
>class AST:
>  def __init__(self, owner, kids=None):
>    self.owner = owner
>    self.kids = kids
>    if kids is None:
>      self.kids = []
>  def add(self, kid):
>    self.kids.append(kid)
>  def cleanup(self):
>    for kid in self.kids:
>      kid.cleanup()
>    self.owner = None
>
>...which obviously requires an explicit call to root.cleanup() 
>when you're done.
>
>I-suppose-I-could-charge-Andy-for-that-<wink>-ly y'rs
>
>- Gordon
I already had the obvious programmer failing solution :( I was hoping
for some super meta programming solution which avoids the cycle somehow.

Andy doesn't want to use acquisition which would probably solve the
problem in a pinch.
-- 
Robin Becker




More information about the Python-list mailing list