Skip to content

gh-148722: Make code objects support cyclic GC#151155

Open
iamrajhans wants to merge 1 commit into
python:mainfrom
iamrajhans:issue-148722-code-gc-cycle
Open

gh-148722: Make code objects support cyclic GC#151155
iamrajhans wants to merge 1 commit into
python:mainfrom
iamrajhans:issue-148722-code-gc-cycle

Conversation

@iamrajhans

@iamrajhans iamrajhans commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Fix code-object reference cycles in GIL-enabled builds by making code objects participate in cyclic garbage collection.

The change uses GC allocation and deallocation for code objects in all builds, enables tp_traverse, and visits co_consts. It also adds a regression test that verifies a cycle from co_consts back to the code object is collected.

Closes #148722.

Tests:

  • make -j8
  • ./python.exe -m test test_code test_marshal test_gc
  • Original issue reproducer

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reference leak in code object with reference loop

1 participant