Search notes:

Python: sys.getrefcount(obj)

sys.getrefcount(obj) returns the reference counter of the object obj.
Because calling sys.getrefcount(obj) also increases the reference counter of obj for the duration of the call, sys.getrefcount(obj) returns a number that is at least 2.
import sys

class CLS: pass

obj_ref_1 = CLS()

print(sys.getrefcount(obj_ref_1)) # -> 2

obj_ref_2 = obj_ref_1
obj_ref_3 = obj_ref_1

print(sys.getrefcount(obj_ref_1)) # -> 4

obj_ref_1 = CLS()

print(sys.getrefcount(obj_ref_1)) # -> 2
print(sys.getrefcount(obj_ref_2)) # -> 3
Github repository about-Python, path: /standard-library/sys/getrefcount.py

See also

Using ctypes to get an object's reference counter
sys

Index