Q20: How does Python manage memory (Reference Counting vs Generational GC)?
Python memory management relies on two layers:
- Reference Counting: Increments/decrements object reference counters. Deallocates objects immediately when references drop to 0.
- Generational Cyclic GC: Detects and breaks cyclic reference graphs across 3 generation tiers (Gen 0, Gen 1, Gen 2) using mark-and-sweep passes.
Reference Counting & Generational Garbage Collector
Key Takeaways
- Reference counting handles immediate deallocation.
- Generational GC breaks cyclic references (where objects reference each other).
Knowledge Check
Which issue CANNOT be resolved by Reference Counting alone, requiring the Generational Garbage Collector?