Skip to content

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

Merged
agneszitte merged 2 commits into
release/stable/6.7from
dev/xygu/20261102/win32-uia-owner-leak-6.7
Nov 2, 2026
Merged

agneszitte merged 2 commits into
release/stable/6.7from
dev/xygu/20261102/win32-uia-owner-leak-6.7

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: partial backport of #23722, same change as #25942 for 6.8 (related: unoplatform/kahua-private#564)

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 release/stable/6.7. 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 (181f20c2aa) and passes with it (087fb0efd4).

PR Checklist ✅

🤖 Generated with Claude Code

Xiaoy312 and others added 2 commits November 2, 2026 14:04
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]>
(cherry picked from commit 18ead23)
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]>
(cherry picked from commit c5e4707)
@agneszitte
agneszitte merged commit c7dfa23 into release/stable/6.7 Nov 2, 2026
43 of 46 checks passed
@agneszitte
agneszitte deleted the dev/xygu/20261102/win32-uia-owner-leak-6.7 branch November 2, 2026 21:40
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.

2 participants