Python's GC: The Default Generation Thresholds
Python's garbage collector uses default thresholds of (700, 10, 10) for generations 0, 1, and 2 respectively, meaning a collection for generation 0 is triggered after 700 new object allocations, and collections for older generations are less frequent.
The top 3
- Python's GC: Default (700, 10, 10) Thresholds: Python's generational garbage collector defaults to a (700, 10, 10) threshold for generations 0, 1, and 2, respectively, which dictates how frequently each generation is checked for unreferenced objects.
- How Thresholds Trigger Full GC Scans: Generation 0 collection triggers when net allocations (allocations minus deallocations) exceed 700; Generation 1 collects after 10 Generation 0 cycles; and Generation 2 (a full collection) runs after 10 Generation 1 cycles.
- Optimizing Performance: Custom GC Thresholds: Developers can significantly impact application performance by tuning the default GC thresholds using `gc.set_threshold()`, with one case demonstrating 20% faster responses by increasing the generation 0 threshold from 700 to 50,000.
Sources
Open the full topic