Ticket #14506: test_gc_refcount.py

File test_gc_refcount.py, 459 bytes (added by Tom Goddard, 21 months ago)

Python script to look for low reference counts.

Line 
1# See if garbage collector objects and references matches reference counts
2
3import gc
4gc.collect()
5gc.disable()
6
7objects = gc.get_objects()
8print (f'Garbage collector sees {len(objects)} objects')
9
10from sys import getrefcount
11for 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
19gc.enable()