gc
Control the current VM's tracing garbage collector.
import gc
cycle = []
cycle.append(cycle)
del cycle
reclaimed = gc.collect()
assert type(reclaimed) is int
assert reclaimed >= 1
Disabling automatic collection does not stop allocation or prevent explicit
collect()/collect_hint() calls. A frame-driven application can disable
automatic collection, call collect_hint() at an appropriate frame boundary,
and re-enable it when leaving that mode. Memory may grow between collections;
measure the effect before adopting this policy.
untrack() is an advanced optimization for containers whose contents do not
need tracing, such as a list containing only integer values. If an untracked
container later contains GC-managed objects, its children can be reclaimed
while still in use. Track it again before storing such values.
Native code must also keep references visible to the collector; see C API lifetimes. Full declarations: gc.pyi.