GC: Implementation does not match behavior documented on gc.set_threshold
#122862
Labels
docs
Documentation in the Doc dir
gc.set_threshold
#122862
Bug report
Bug description:
The documentation of
gc.set_threshold
states:This doesn't seem to be accurate. Looking at the implementation, it appears that
young.count
is being used to tracknumber of allocations minus the number of deallocations
. However it doesn't actually track this due to theif (gcstate->young.count > 0)
check here: https://github.com/python/cpython/blob/3.13/Python/gc.c#L2119.As a concrete example, suppose
threshold0=500
. Suppose the GC runs andyoung.count
is reset to 0, then 500 deallocations happen (by object ref counts dropping to 0), then 500 allocations happen. According to the documentation the GC would not run in this case, because the difference between allocations and deallocations is 0. However the actual tracked number inyoung.count
will be 500, and GC will trigger.I'm unsure which is the expected behavior; the documented one or the implemented one, but it does appear that the two do not currently agree.
CPython versions tested on:
3.13
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: