Circular refs

Darrell news at dorb.com
Mon Sep 27 11:40:50 EDT 1999


Instead of letting Noisy hold the offending references keep them in a
dictionary and let Noisy hold a key to find it.

OR:
Untested code that I half expect to be beaten up for.
Add a destroy method to class Noisy that cleans out it's data members.
def destroy(self):
    for k in self.__dict__.keys():
         setattr(self, k, None)

Also check out tools for finding this sort of thing such as cyclops which is
a variation on plumbo.

--
--Darrell
Adrian Eyre <a.eyre at optichrome.com> wrote in message
news:000501bf08f9$f25e79e0$3acbd9c2 at peridot.optichrome.com...
> Is there a reasonable fix for this?
>
> >>> class Noisy:
> ...     def __init__(self, name):
> ...         self._name = name
> ...         print "Created " + self._name
> ...     def __del__(self):
> ...         print "Destroyed " + self._name
> ...
> >>> a = Noisy("a")
> Created a
> >>> b = Noisy("b")
> Created b
> >>> del a
> Destroyed a
> >>> del b
> Destroyed b
>
> Fair enough, but...
>
> >>> a = Noisy("a")
> Created a
> >>> b = Noisy("b")
> Created b
> >>> a.b = b
> >>> b.a = a
> >>> del a
> >>> del b
> [Sound of memory dripping onto the floor]
>
> --------------------------------------------
> Adrian Eyre <mailto:a.eyre at optichrome.com>
> Optichrome Computer Solutions Ltd
> Maybury Road, Woking, Surrey, GU21 5HX, UK
> Tel: +44 1483 740 233  Fax: +44 1483 760 644
> http://www.optichrome.com
> --------------------------------------------
>






More information about the Python-list mailing list