Circular references and python

François Pinard pinard at
Mon Jan 21 06:00:05 CET 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, = prev,next

> [...] To allow breaking the cycles, you can do

>   def clear(self):
>     if
> = None        # or self.prev = None

Here is my question.  Instead of: = 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

More information about the Python-list mailing list