Skip to content

fix: garbage collection issues for #[pyclass(dict)] - #6206

Merged
davidhewitt merged 1 commit into
PyO3:mainfrom
rewitt94:pyclass-dict-gc-fixes
Jul 24, 2026
Merged

fix: garbage collection issues for #[pyclass(dict)]#6206
davidhewitt merged 1 commit into
PyO3:mainfrom
rewitt94:pyclass-dict-gc-fixes

Conversation

@rewitt94

@rewitt94 rewitt94 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

PR contains two fixes for GC of #[pyclass(dict)]

  1. #[pyclass(dict)] without a user defined __traverse__ function did not define a required GC slots on the PyTypeObject to become discoverable to the cyclic garbage collector.
    Solution: now defined regardless in create_type_object.

  2. Early returns (when there are live references we can early return i.e. tell cyclic GC we can't clear) in_call_traverse did not drop lock / disarm trap which would cause a crash.
    Solution: Logic is now nested into inner function that can safely early return.

Related to issue #5953 / PR #6198 (no overlap with PR)

@rewitt94
rewitt94 force-pushed the pyclass-dict-gc-fixes branch from fa6a510 to f3369bc Compare July 15, 2026 14:32
@davidhewitt davidhewitt mentioned this pull request Jul 24, 2026
11 tasks

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know towncrier supported .1.md etc for additional files; I just verified this works with towncrier build, nice 😂

@davidhewitt
davidhewitt added this pull request to the merge queue Jul 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 24, 2026
@davidhewitt
davidhewitt added this pull request to the merge queue Jul 24, 2026
Merged via the queue into PyO3:main with commit 2188265 Jul 24, 2026
57 checks passed
@jonasdedden

jonasdedden commented Jul 25, 2026

Copy link
Copy Markdown

@davidhewitt @rewitt94 I think a specific test here introduced flakyness in CI (also reproducible locally) => #6243

I'm not an expert on this, but I left a "Suggested fix" section with various approaches.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants