Skip to content

Fix Context memory leak introduced by PR #3208#3221

Closed
idavis wants to merge 1 commit into
mainfrom
iadavis/3208-leak-fixes
Closed

Fix Context memory leak introduced by PR #3208#3221
idavis wants to merge 1 commit into
mainfrom
iadavis/3208-leak-fixes

Conversation

@idavis
Copy link
Copy Markdown
Collaborator

@idavis idavis commented May 12, 2026

PR #3208 created two unbreakable reference cycles per qdk.Context:

  • bound-method callbacks passed to the native Interpreter, plus per-callable _callable_fn closures that captured self, formed Python <-> Rust cycles outside the cyclic GC's reach (PyO3 pyclasses default to no GC integration).
  • Per-context synthetic namespace modules registered in sys.modules with no cleanup path until the Context was explicitly disposed.

PR #3208 created two unbreakable reference cycles per qdk.Context:
- bound-method callbacks passed to the native Interpreter, plus
  per-callable `_callable_fn` closures that captured `self`, formed
  Python <-> Rust cycles outside the cyclic GC's reach (PyO3 pyclasses
  default to no GC integration).
- Per-context synthetic namespace modules registered in sys.modules
  with no cleanup path until the Context was explicitly disposed.
Comment thread source/qdk_package/qdk/_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
Comment thread source/qdk_package/tests/test_context.py Dismissed
@swernli swernli closed this May 12, 2026
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