Skip to content

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

Open
rewitt94 wants to merge 1 commit into
PyO3:mainfrom
rewitt94:pyclass-dict-gc-fixes
Open

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

Conversation

@rewitt94

@rewitt94 rewitt94 commented Jul 15, 2026

Copy link
Copy Markdown

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
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.

1 participant