Skip to content

gh-122862: Fix description of the GC allocation counter in set_threshold() docs - #156877

Open
owenthcarey wants to merge 1 commit into
python:mainfrom
owenthcarey:gh-122862-gc-threshold-docs
Open

gh-122862: Fix description of the GC allocation counter in set_threshold() docs#156877
owenthcarey wants to merge 1 commit into
python:mainfrom
owenthcarey:gh-122862-gc-threshold-docs

Conversation

@owenthcarey

@owenthcarey owenthcarey commented Sep 3, 2026

Copy link
Copy Markdown

The gc.set_threshold() documentation says the collector tracks "the number of allocations minus the number of deallocations" since the last collection. The implementation doesn't quite do that: the generation 0 counter is incremented on each allocation and decremented on each deallocation, but it's never decremented below zero, and it's reset when a collection runs. This means deallocations that happen before allocations don't offset them, as described in the issue.

This rewrites the sentence to describe the actual behavior. It also fixes the missing "of" in "the number object allocations".

Fixes #122862

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34369682 | 📁 Comparing 50e03c5 against main (161054c)

  🔍 Preview build  

1 file changed
± library/gc.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

GC: Implementation does not match behavior documented on gc.set_threshold

1 participant