Garbage Collection
The gc module finds and frees groups of objects that reference each other (cycles).
Intermediate
Reference counting can't free cycles (A→B→A). CPython's generational collector periodically scans container objects. gc.collect() forces a collection; gc.disable() can help short-lived batch jobs. weakref avoids creating cycles in caches and observers.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.