Repository navigation
Fix Python WinUI teardown with explicit process module ownership - #156
Merged
Merged
Conversation
Retain validated WinUI implementation module ownership for Python until process termination, deduplicate activation fallback references, and preserve normal COM object and apartment cleanup. Add targeted native ownership, MTA, and Tokio teardown regressions without changing public Python or JavaScript APIs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
Let the Windows loader resolve the full dependency path and compare retained HMODULE values instead of case-sensitive path spellings. Keep rejecting distinct runtime modules and add real loader regressions for filename and directory casing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Yu Leng (moooyo)
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #116.
Summary
Prevent Python WinUI teardown from releasing Controls' static XAML references through an already-unloaded
Microsoft.UI.Xaml.dll.Microsoft.UI.Xaml.*activation and XAML Application composition paths.LoadLibraryreferences into the same owner instead of accumulating them per activation; release failed and competing candidates.Lifecycle contract
After Python first uses WinUI, the ordinary path retains one owned XAML DLL reference until process termination. A required fallback retains at most one reference per validated implementation module. This deliberately retains the module mapping and its static state, not application-held COM objects or factories.
Windows, events, projected values, and successful apartment initialization calls still receive normal cleanup. There is no PIN flag, early
atexitunload, skippedRoUninitialize, new public Python API, second production executor, or sample nesting change. JS and ordinary WinRT/COM keep their existing activation policy; ordinary imports/Uri usage do not load XAML or CoreMessaging.In-process unloading/hot replacement of the retained WinUI implementation is not supported. This is distinct from updating application UI/XAML, and does not assert that WinUI lacks thread-level shutdown or that arbitrary native hosts bypassing dynwinrt are fixed.
Validation
Validated on Windows ARM64 build 28020 with CPython 3.13.15, freshly built production/test wheels, regenerated wrappers, WinUI metadata 2.3.0 and Foundation 2.3.5. The actual selected runtime was
Microsoft.WindowsAppRuntime.2_2.4.0.0_arm64__8wekyb3d8bbwe(XAML 3.2.0.2511, Controls 3.2.3.2608).run.ps1 -Python <ARM64 Python> -Smoke -Major 2 -Minor 3: actual exit 0, also independently reproduced during review.Public Python exports and stubs, JS source, codegen source, and the Hello World application/launch scripts are unchanged.