all Python 3gcfunction
gc.get_objects()
introspection
Returns a list of all objects tracked by the collector. A tool for debugging leaks.
Syntax
gc.get_objects(generation=None)
Only containers appear here: numbers, strings and many simple objects are not tracked and will be missing. The list is huge (tens of thousands of objects) and keeps them alive while it exists — pick what you need and drop it at once. The generation argument depended on the version (3.14.0–3.14.4 had no generation 1), so do not pass it without need.
Examples
import gc
class Session:
pass
keep = [Session() for _ in range(3)]
print(sum(isinstance(o, Session) for o in gc.get_objects())) # → 3
print(len(gc.get_objects())) # → ? десятки тысяч
See also
Open in the full glossarydocs.python.orgReport an inaccuracy