Skip to content

fix(win32): Fix UIA provider memory leak (partial backport of #23722) - #25942

Merged
agneszitte merged 2 commits into
servicing/6.8from
dev/xygu/20261102/win32-uia-owner-leak-6.8
Nov 2, 2026
Merged

agneszitte merged 2 commits into
servicing/6.8from
dev/xygu/20261102/win32-uia-owner-leak-6.8

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: partial backport of #23722

PR Type:

🐞 Bugfix

What changed? 🚀

On Win32, an element removed from the tree could stay in memory for as long as anything still held a COM reference to its UI Automation provider. An invalidated Win32RawElementProvider kept a strong reference to its UIElement, so the whole subtree stayed alive. The retention path in a memory dump is [COM/WinRT Objects] → Win32RawElementProvider → <element>.

This backports the provider-lifecycle part of #23722 to servicing/6.8. The rest of that PR (a11y parity work) is left out.

  • Win32RawElementProvider.Invalidate() clears its reference to the element.
  • Reads of the element go through ConnectedOwner, which throws UIA_E_ELEMENTNOTAVAILABLE on an invalidated provider, the same error UIA clients already get from ThrowIfDisconnected. DescribeElement(), used only for logging, returns a placeholder instead.
  • Win32Accessibility skips the provider's element when it has been cleared (lookup-table cleanup, live-region announcement).

The new runtime test Given_Win32Accessibility.When_Removed_Element_Provider_Is_Still_Referenced_Owner_Is_Collected holds a COM reference to a removed element's provider and checks that the element is collected. Locally on Skia Win32 (SamplesApp.Skia.Generic, net10.0), it fails without the fix (18ead235af) and passes with it (c5e470712b).

PR Checklist ✅

🤖 Generated with Claude Code

Xiaoy312 and others added 2 commits November 2, 2026 13:08
A UIA provider that a client still references after its element left the
tree must not keep that element alive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An invalidated Win32RawElementProvider kept a strong reference to its
UIElement, so any outstanding COM reference to the provider leaked the
whole element subtree. Clear the owner on invalidation and fail owner
reads with UIA_E_ELEMENTNOTAVAILABLE.

Backport of the provider lifecycle part of #23722.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312 Xiaoy312 changed the title fix(win32): Release UIA provider owner on invalidate (backport #23722) fix(win32): Fix UIA provider memory leak (partial backport of #23722) Nov 2, 2026
@unoplatform unoplatform deleted a comment from mergify Bot Nov 2, 2026
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

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.

5 participants