Skip to content

fix(input): Drop a released pointer's gesture recognizers - #25589

Merged
ajpinedam merged 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/pointer-recognizer-queue
Oct 24, 2026
Merged

ajpinedam merged 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/pointer-recognizer-queue

Conversation

@mikernet

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25588

PR Type:

🐞 Bugfix

What changed? 🚀

When a manipulation starts on a UIElement, the input manager queues that element's gesture recognizer for the pointer type, and it removes the queue when the pointer is released or cancelled. PointerTypePseudoDictionary.Remove only cleared the presence flag and left the queue in its slot. So the element that last started a manipulation with a given pointer type stayed reachable from the input manager, with its visual tree and DataContext, until another manipulation with that pointer type replaced the queue. That may never happen.

In a WebAssembly app, a CommunityToolkit DataGrid scrolled with the mouse kept its page alive this way after the user navigated away: 80 MB of a 282 MB managed heap (see the issue for the heap dump path).

Remove now clears the stored value too, as ClearForFataError already did.

Tests

Given_InputManager.When_ManipulableElementReleasedAndRemoved_Then_Collected:

  • Setup: it loads a Border with ManipulationMode = All, presses and releases the mouse on it, and checks that ManipulationStarting fired, so the recognizer really was registered.
  • Check: it then removes the element from the tree and asserts that the element is collected.
  • The extra mouse move: the test moves the mouse by 1px before collecting. That releases PointerRoutedEventArgs.LastPointerEvent, which holds the last event's source until the next pointer event, and doesn't start a manipulation.

Results on Skia desktop:

  • New test: fails on master and passes with this PR, 20 of 20 runs with retries off.
  • Given_InputManager: 24 passed, 10 skipped.
  • Given_ScrollViewer: 77 passed.
  • Given_ScrollViewer_Zoom: 15 passed.
  • Given_GestureRecognizer: 2 passed.
  • Given_ManipulationExtensions: 3 passed.
  • Given_UIElement: 543 passed and 3 failed. The failures are When_Child_ActualOffset, When_Nested_Child_ActualOffset and When_Root_Margin_ActualOffset, which also fail on master with the same values on this machine (display scaling).

Not changed

These were found while checking what else holds a released element. Each one is replaced or cleared by the next pointer event or press, so none of them is a lasting leak:

  • PointerRoutedEventArgs.LastPointerEvent, and its copy in CoreWindow.LastPointerEvent: until the next pointer event.
  • Finished direct manipulations (touch and pen): they stay in DirectManipulationCollection until Scavenge() runs on the next pointer enter or press.
  • _pendingDirectManipulationCancelRequester: until the next press.

PR Checklist ✅

Press and release the mouse on an element with a ManipulationMode,
remove it from the tree, and check that the input manager does not
keep it alive. The test moves the mouse before collecting so that
PointerRoutedEventArgs.LastPointerEvent no longer points at it.
When a manipulation starts, the element's GestureRecognizer is queued
in the input manager for its pointer type, and the queue is removed on
release or cancel. PointerTypePseudoDictionary.Remove only cleared the
presence flag, though, and left the queue in its slot. The element
that last started a manipulation with a given pointer type therefore
stayed reachable from the input manager, with its visual tree and
DataContext, until another manipulation with that pointer type
replaced the queue, which might never happen.

Remove now clears the stored value too.

Fixes unoplatform#25588
Copilot AI balanced review requested due to automatic review settings October 20, 2026 10:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow fix removes the retaining reference without changing lookup behavior and includes focused regression coverage.

No open issues 🎉

What changed in this PR

Fixes #25588 by releasing stored gesture recognizers when a pointer is released or cancelled, preventing the input manager from retaining detached elements and their visual trees.

Changes:

  • Clear the stored value as well as the presence flag when removing a pointer-type entry.
  • Add a regression test verifying that a manipulated element can be collected after removal.
File Description
src/​Uno.UI/​UI/​Xaml/​Internal/​InputManager.Pointers.ManagedDirectManip.cs Clears the reference retained by a removed entry.
src/​Uno.UI.RuntimeTests/​Uno/​UI/​Xaml/​Core/​Given_InputManager.cs Tests collection after mouse release and element removal.

Review effort: Balanced

mikernet added a commit to Singulink/uno that referenced this pull request Oct 20, 2026
Port of unoplatform#25589 (986d906 and d412796), for
unoplatform#25588.

PointerTypePseudoDictionary.Remove only cleared the presence flag and
left the queue of recognizers in its slot, so the element that last
started a manipulation with a pointer type stayed reachable from the
input manager, with its visual tree and DataContext, until another
manipulation replaced the queue. In DropDoc's WebAssembly app, a
DataGrid scrolled with the mouse kept its departed page alive this way
(80 MB). Remove now clears the stored value too.

- Test: Given_InputManager.When_ManipulableElementReleasedAndRemoved_Then_Collected.
@mikernet

Copy link
Copy Markdown
Contributor Author

Could this be backported to servicing/6.8 once it's merged? The same code is in 6.8 (PointerTypePseudoDictionary.Remove at 5efcb98). The leak is what kept a DataGrid page alive in our WebAssembly app on 6.8, and the change applies cleanly there. We've been running the same commit and test on a 6.8 build: the test fails without the fix and passes with it.

@agneszitte
agneszitte requested a review from dr1rrb October 20, 2026 20:08
@agneszitte agneszitte assigned ajpinedam and unassigned ajpinedam Oct 20, 2026
@agneszitte
agneszitte requested a review from ajpinedam October 20, 2026 20:08
@agneszitte

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

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

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 240473 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSpanningRectsPage.png
    • AppWindowPresenters.png
    • ArcSegment.png
    • AuthenticationBroker_Cancel.png-dark
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_AutomationId.png
    • AutomationProperties_Relations.png
    • AutomationProperties_StructureAndProps.png-dark
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png

@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@ajpinedam
ajpinedam merged commit ab14387 into unoplatform:master Oct 24, 2026
46 checks passed
@ajpinedam

Copy link
Copy Markdown
Contributor

@mergify backport servicing/6.8

@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/6.8

✅ Backports have been created

Details

@agneszitte

Copy link
Copy Markdown
Member

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

agneszitte added a commit that referenced this pull request Nov 3, 2026
…6.7/pr-25589

fix(input): Drop a released pointer's gesture recognizers (backport #25589)
agneszitte added a commit that referenced this pull request Nov 3, 2026
…r-25589

fix(input): Drop a released pointer's gesture recognizers (backport #25589)
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.

[Skia] The input manager keeps the element of the last manipulation alive after its pointer is released

7 participants