Repository navigation
Conversation
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
There was a problem hiding this comment.
🟢 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
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.
|
Could this be backported to |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 240473 found UI Test snapshots differences: Details
|
|
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. |
|
@mergify backport servicing/6.8 |
✅ Backports have been createdDetails
|
|
@Mergifyio backport release/stable/6.7 |
✅ Backports have been createdDetails
|
…6.7/pr-25589 fix(input): Drop a released pointer's gesture recognizers (backport #25589)
…r-25589 fix(input): Drop a released pointer's gesture recognizers (backport #25589)
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.Removeonly 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 andDataContext, until another manipulation with that pointer type replaced the queue. That may never happen.In a WebAssembly app, a CommunityToolkit
DataGridscrolled 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).Removenow clears the stored value too, asClearForFataErroralready did.Tests
Given_InputManager.When_ManipulableElementReleasedAndRemoved_Then_Collected:BorderwithManipulationMode = All, presses and releases the mouse on it, and checks thatManipulationStartingfired, so the recognizer really was registered.PointerRoutedEventArgs.LastPointerEvent, which holds the last event's source until the next pointer event, and doesn't start a manipulation.Results on Skia desktop:
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 areWhen_Child_ActualOffset,When_Nested_Child_ActualOffsetandWhen_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 inCoreWindow.LastPointerEvent: until the next pointer event.DirectManipulationCollectionuntilScavenge()runs on the next pointer enter or press._pendingDirectManipulationCancelRequester: until the next press.PR Checklist ✅
Screenshots Compare Test Runresults.