Circular references and python
François Pinard
pinard at iro.umontreal.ca
Mon Jan 21 00:00:05 EST 2002
[Neel Krishnaswami]
> Manually freeing memory is ugly and error-prone. Don't do it. :)
It might be the simplest approach in the long run, but there are still
many 1.5.2 implementations around, and you might want to write portably.
[Martin von Loewis]
> Consider
> class ListItem:
> def __init__(self,next,prev):
> self.prev,self.next = prev,next
> [...] To allow breaking the cycles, you can do
> def clear(self):
> if self.next:
> self.next.clear()
> self.next = None # or self.prev = None
Here is my question. Instead of:
self.next = None
could one systematically write:
del self.next
? Is there any advantage, speed or otherwise, using one over the other?
The first might look more speedy, but since `del' is doomed to occur anyway
when the object is finalised, it is not so evident which is best.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list