Circular references and python
pinard at iro.umontreal.ca
Mon Jan 21 06:00:05 CET 2002
> 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]
> 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 = None # or self.prev = None
Here is my question. Instead of:
self.next = None
could one systematically write:
? 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