You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incremental GC does not collect garbage as soon as expected #142002
File "/home/thomas/python/python/main/Lib/contextlib.py", line 85, in inner
return func(*args, **kwds)
File "/home/thomas/python/python/main/Lib/test/test_gc.py", line 1573, in test_bug1055820d
self.fail("gc didn't happen after 50000 iterations")
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: gc didn't happen after 50000 iterations
Reverting GH-140262 seems to fix this. It is possible this is related to GH-141890 as well.
What is "expected" in this case?
Since the test in question produces no cycles, an optimal cycle collector would always fail this test regardless of how large we set the threshold.
It is the test that is broken here.
We should either increase the threshold or, better still, change the test to produce cycles.
What is "expected" in this case? Since the test in question produces no cycles, an optimal cycle collector would always fail this test regardless of how large we set the threshold.
It is the test that is broken here. We should either increase the threshold or, better still, change the test to produce cycles.
The test creates 50,000 new list objects. Are you saying the GC somehow knows these are not reference cycles without running? Changing the test to create lists that reference themselves (and be cycles) would fail in the same way. This is a strange argument in how the test is broken to my mind.
This test, and I believe other tests that rely on the GC_Detector, depends heavily on the size of the global roots.
For incremental GC, there are two phases: MARK and COLLECT.
In this test, we call gc.collect before the loop, it runs completed_scavenge, sets the work_to_do value to zero and switchs GC to the MARK phase. In the loop the garbage collection runs when we create 2000 objects in the young generation. Then, we go to the MARK phase. In this phase, we mark all live roots and adjust value of the work_to_do, which becomes negative (I suppose a large negative). Then we switch phase to the COLLECT and stop this collection iteration. Afterwards, we repeatedly create objects in the young generation. This leads to GC runs. We check the work_to_do value, which is still negative, so we return early from GC. It seems that we cannot reach a positive work_to_do value in 50_000 iterations, and the test fails.
Activity
markshannon commentedon Dec 1, 2025
What is "expected" in this case?
Since the test in question produces no cycles, an optimal cycle collector would always fail this test regardless of how large we set the threshold.
It is the test that is broken here.
We should either increase the threshold or, better still, change the test to produce cycles.
nascheme commentedon Dec 3, 2025
The test creates 50,000 new list objects. Are you saying the GC somehow knows these are not reference cycles without running? Changing the test to create lists that reference themselves (and be cycles) would fail in the same way. This is a strange argument in how the test is broken to my mind.
sergey-miryanov commentedon Dec 3, 2025
This test, and I believe other tests that rely on the GC_Detector, depends heavily on the size of the global roots.
For incremental GC, there are two phases: MARK and COLLECT.
In this test, we call
gc.collectbefore the loop, it runscompleted_scavenge, sets thework_to_dovalue to zero and switchs GC to the MARK phase. In the loop the garbage collection runs when we create 2000 objects in the young generation. Then, we go to the MARK phase. In this phase, we mark all live roots and adjust value of thework_to_do, which becomes negative (I suppose a large negative). Then we switch phase to the COLLECT and stop this collection iteration. Afterwards, we repeatedly create objects in the young generation. This leads to GC runs. We check thework_to_dovalue, which is still negative, so we return early from GC. It seems that we cannot reach a positivework_to_dovalue in 50_000 iterations, and the test fails.