all Python 3gcfunction
gc.get_referents()
introspection
Returns the objects directly referred to by the arguments: list items, dict keys and values, and so on.
Syntax
gc.get_referents(*objs)
You only see what the object reports to the collector through its C-level traversal; references that cannot form a cycle may be left out. The order is not guaranteed (for a list it is reversed), so compare sorted or as a set. For a dict with string keys only the values come back — strings cannot form cycles and are not reported; for a class instance you get the attribute values and the class itself.
Examples
import gc
print(sorted(gc.get_referents([3, 1, 2]))) # → [1, 2, 3]
print(gc.get_referents({'a': 1})) # → [1] — строкового ключа нет
See also
Open in the full glossarydocs.python.orgReport an inaccuracy