Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Simplistic demonstration of Python GC behaviour
import gc
import weakref
class Object(object): pass
l = [Object()]
l[0].l = l
REFS = weakref.WeakKeyDictionary()
REFS[l[0]] = True
del l
print (list(REFS.keys()))
print (list(REFS.keys()))
gvx commented

Output in both Python 2.6.6 and 3.2:

[<__main__.Object object at 0x258d690>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.