Content-Length: 292005 | pFad | http://github.com/python/cpython/pull/136189/commits/900022b72f4dc5e49a6ad7367b704763894eff35

30 gh-135552: Make the GC clear weakrefs later. by nascheme · Pull Request #136189 · python/cpython · GitHub
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 16 commits into
base: main
Choose a base branch
from
Open
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
Revise NEWS.
  • Loading branch information
nascheme committed Jul 8, 2025
commit 900022b72f4dc5e49a6ad7367b704763894eff35
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
Fix two bugs related to the interaction of weakrefs and the garbage
collector. The weakrefs in the ``tp_subclasses`` dictionary are needed in
order to correctly invalidate type caches (for example, by calling
``PyType_Modified()``). Clearing weakrefs before calling finalizers causes
the caches to not be correctly invalidated. That can cause crashes since the
caches can refer to invalid objects. This is fixed by deferring the
clearing of weakrefs to classes and without callbacks until after finalizers
are executed.

The second bug is caused by weakrefs created while running finalizers. Those
weakrefs can be outside the set of unreachable garbage and therefore survive
the ``delete_garbage()`` phase (where ``tp_clear()`` is called on objects).
Those weakrefs can expose to Python-level code objects that have had
``tp_clear()`` called on them. See GH-91636 as an example of this kind of
bug. This is fixes be clearing all weakrefs to unreachable objects after
finalizers have been executed.
Fix a bug caused by the garbage collector clearing weakrefs too early. The
weakrefs in the ``tp_subclasses`` dictionary are needed in order to correctly
invalidate type caches (for example, by calling ``PyType_Modified()``).
Clearing weakrefs before calling finalizers causes the caches to not be
correctly invalidated. That can cause crashes since the caches can refer to
invalid objects. Defer the clearing of weakrefs without callbacks until after
finalizers are executed.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/136189/commits/900022b72f4dc5e49a6ad7367b704763894eff35

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy