On 18/05/2013 3:18pm, Antoine Pitrou wrote:
It works fine:
$ ./python sbt.py
<__main__.Node object at 0x7f3acbf8f400> <__main__.Node object at
0x7f3acbf8f878>
<__main__.Node object at 0x7f3acbf8f878> <__main__.Node object at
0x7f3acbf8f400>
The reason is that, when you execute "del self.next", this removes the
last reference to self.next and destroys it immediately.
So even more contrived:
class Node:
def __init__(self, x):
self.x = x
self.next = None
def __del__(self):
print(self.x, self.next.x)
del self.x
a = Node(1)
b = Node(2)
a.next = b
b.next = a
del a, b
gc.collect()
--
Richard
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com