Ticket #14506: test_gc_refcount.py
File test_gc_refcount.py, 459 bytes (added by , 21 months ago) |
---|
Line | |
---|---|
1 | # See if garbage collector objects and references matches reference counts |
2 | |
3 | import gc |
4 | gc.collect() |
5 | gc.disable() |
6 | |
7 | objects = gc.get_objects() |
8 | print (f'Garbage collector sees {len(objects)} objects') |
9 | |
10 | from sys import getrefcount |
11 | for i,o in enumerate(objects): |
12 | r = gc.get_referrers(o) |
13 | nr = len(r) |
14 | rc = getrefcount(o) |
15 | if rc < nr+1: |
16 | print(f'object {i}, {nr} referrers, ref count {rc}, type {type(o)}, object {o}') |
17 | break |
18 | |
19 | gc.enable() |