Skip to content

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

Merged
agneszitte merged 2 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25589
Nov 3, 2026
Merged

agneszitte merged 2 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-25589

Conversation

@mergify

@mergify mergify Bot commented Nov 3, 2026

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 ✅


This is an automatic backport of pull request #25589 done by [Mergify](https://mergify.com).

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.

(cherry picked from commit 986d906)
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 #25588

(cherry picked from commit d412796)
@unodevops

Copy link
Copy Markdown
Contributor

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

@agneszitte
agneszitte merged commit 29c8ee0 into release/stable/6.7 Nov 3, 2026
41 of 46 checks passed
@agneszitte
agneszitte deleted the mergify/bp/release/stable/6.7/pr-25589 branch November 3, 2026 06:35
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