Weak reference: Difference between revisions

Content deleted Content added
added python3 code
Line 103:
public Node next;
}
</source>
 
===Python3===
<source lang=python3>
>>> import weakref
>>> import gc
>>> class Egg:
... def spam(self):
... print("I'm alive!")
...
>>> obj = Egg()
>>> weak_obj = weakref.ref(obj)
>>> weak_obj().spam()
I'm alive!
>>> obj = "Something else"
>>> gc.collect()
35
>>> weak_obj().spam()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'spam'
</source>