10000 gh-135552: Make the GC clear weakrefs later. by nascheme · Pull Request #136189 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135552: Make the GC clear weakrefs later. #136189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add comment about wrlist iteration.
This is a bit trickly because the wrlist can be changing as we
iterate over it.
  • Loading branch information
nascheme committed Jul 3, 2025
commit 8a553d14a7fe71a303390b18357a54e6088770ae
3 changes: 3 additions & 0 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ handle_weakref_callbacks(PyGC_Head *unreachable, PyGC_Head *old)
*/
PyWeakReference *next_wr;
for (PyWeakReference *wr = *wrlist; wr != NULL; wr = next_wr) {
// Get the next list element to get iterator progress if we omit
// clearing of the weakref (because _PyWeakref_ClearRef changes
// next pointer in the wrlist).
next_wr = wr->wr_next;

// Weakrefs with callbacks always need to be cleared before
Expand Down
3 changes: 3 additions & 0 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,9 @@ find_weakref_callbacks(struct collection_state *state)
// that must be called into wrcb_to_call.
PyWeakReference *next_wr;
for (PyWeakReference *wr = *wrlist; wr != NULL; wr = next_wr) {
// Get the next list element to get iterator progress if we omit
// clearing of the weakref (because _PyWeakref_ClearRef changes
// next pointer in the wrlist).
next_wr = wr->wr_next;

// Weakrefs with callbacks always need to be cleared before
Expand Down
0