Skip to content

Instantly share code, notes, and snippets.

@koehlma
Last active January 24, 2016 10:59
Show Gist options
  • Save koehlma/965eab2bb8ac7f2d6a29 to your computer and use it in GitHub Desktop.
Save koehlma/965eab2bb8ac7f2d6a29 to your computer and use it in GitHub Desktop.
gc: collecting generation 2...
gc: objects in each generation: 13 0 5824
gc: collectable <B 0x7f8c86b4ec50>
gc: collectable <dict 0x7f8c86b57248>
finalize b <__main__.A object at 0x7f8c86b4ec18>
gc: done, 3 unreachable, 0 uncollectable, 0.0005s elapsed
gc: collecting generation 2...
gc: objects in each generation: 1 0 5831
gc: done, 0.0005s elapsed
gc: collecting generation 2...
gc: objects in each generation: 1 0 5831
gc: done, 0.0005s elapsed
gc: collecting generation 2...
gc: objects in each generation: 1 0 5831
gc: done, 0.0005s elapsed
gc: collecting generation 2...
gc: objects in each generation: 1 0 5831
gc: done, 0.0005s elapsed
<__main__.B object at 0x7f8c86b4ec50>
[[<__main__.B object at 0x7f8c86b4ec50>, {'a': <__main__.A object at 0x7f8c86b4ec18>, 'b': <__main__.B object at 0x7f8c86b4ec50>}], {'a': <__main__.A object at 0x7f8c86b4ec18>, 'b': <__main__.B object at 0x7f8c86b4ec50>}]
<__main__.A object at 0x7f8c86b4ec18>
[{'a': <__main__.A object at 0x7f8c86b4ec18>, 'b': <__main__.B object at 0x7f8c86b4ec50>}]
import gc
import sys
import weakref
class A: pass
class B: pass
gc.disable()
gc.collect()
gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_LEAK)
a = A()
weakref.finalize(a, print, 'finalize: a', file=sys.stderr).atexit = False
b = B()
b.a = a
b.b = b
weakref.finalize(b, print, 'finalize: b', a, file=sys.stderr).atexit = False
del a
del b
for _ in range(10): gc.collect()
gc.set_debug(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment