all Python 3gcfunction
gc.is_tracked()
introspection
Checks whether the cyclic garbage collector tracks an object. Numbers and strings are not tracked; lists and class instances are.
Syntax
gc.is_tracked(obj)
The collector may 'untrack' non-atomic objects to save work, and the rules depend on the version: an empty dict or a tuple of numbers gives False on some versions and True on others (3.14 and 3.15 changed them). So tests should rely on is_tracked only for stable cases — atoms and lists. Tracking is not lifetime: an untracked number is still freed by reference counting as usual.
Examples
import gc
class P:
pass
print(gc.is_tracked(42), gc.is_tracked('text')) # → False False
print(gc.is_tracked([]), gc.is_tracked(P())) # → True True
print(gc.is_tracked({})) # → ? False до 3.13, True с 3.14
See also
Open in the full glossarydocs.python.orgReport an inaccuracy