Created
October 3, 2012 22:28
-
-
Save gvx/3830294 to your computer and use it in GitHub Desktop.
Simplistic demonstration of Python GC behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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())) | |
| gc.collect() | |
| print (list(REFS.keys())) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output in both Python 2.6.6 and 3.2: