What this Python garbage collection interview question tests
This is a medium-difficulty question about Python's memory management and the interaction between reference counting and garbage collection. It's the kind of question asked at firms where system latency and predictability matter—trading platforms, low-latency data processors, and other performance-critical environments.
The question probes whether you understand the difference between CPython's automatic reference-counting mechanism and its cycle-detecting garbage collector, and what happens when you disable the latter. A strong answer requires you to reason about when objects are actually freed, how circular references behave under different GC states, and the real-world tradeoff between pause-free execution and memory overhead.
- Reference counting vs. tracing garbage collection
- Circular references and object lifecycle
- GC pause behaviour and determinism
- Impact of disabling
gc.disable() on heap fragmentation