Why the default GC generation threshold is set to (700, 10, 10) in Python; And the latter two numbers 10, 10 are so small?
Does such low threshold would result in much more collections?
The thresholds are multipliers relative to the previous generation. From the gc.set_threshold()
documentation:
In order to decide when to run, the collector keeps track of the number object allocations and deallocations since the last collection. When the number of allocations minus the number of deallocations exceeds
threshold0
, collection starts. Initially only generation0
is examined. If generation0
has been examined more thanthreshold1
times since generation1
has been examined, then generation1
is examined as well. Similarly,threshold2
controls the number of collections of generation1
before collecting generation2
.
Bold emphasis mine.
So generation 1 is only run if generation 0 has been run 10 times. Since generation 0 only runs every 700 (delta of allocation - deallocation) cycles, that means generation 1 is run every 10 * 700 == 7.000 cycles. Generation 2 is run every 10 * 10 * 700 == 70.000 cycles.