Repository navigation
Description
Current behavior 🐛
Uno's ItemsRepeater/RecyclePool never clears an element's DataContext when the element is recycled. ViewManager.ClearElementToElementFactory moves ownership to the element factory and recycles the element, but leaves the stale DataContext in place until the element is eventually reused (if ever):
- DataContext set on prepare:
ViewManager.cs#L790-L807— no tracking of whether the repeater was the one setting it. - Clear on recycle:
ViewManager.cs#L166-L215— noDataContextclearing at all.
Current WinUI clears it. ViewManager::ClearElementToElementFactory nulls the DataContext when the repeater set it, tracked by a MustClearDataContext flag on VirtualizationInfo (comment: "We need to clear the datacontext to prevent crashes from happening, however we only do that if we were the ones setting it"). This is the code missing from Uno's port (pinned at microsoft-ui-xaml@d4aeb08):
- Clear on recycle: ViewManager.cpp#L144-L167
- Flag set on prepare: ViewManager.cpp#L805-L844
Uno's Repeater port predates this MUX change.
Measured divergence (via the ItemsRepeater_RecycledSpinner sample from #23447, which builds for the WinAppSDK head): after removing an item whose element is recycled but not reused, the mechanism readout is stillParented=True / dataContextUnchanged=True on Uno vs stillParented=True / dataContextUnchanged=False on real WinUI.
Expected behavior 🎯
Match WinUI: track whether the repeater set the DataContext (MustClearDataContext on VirtualizationInfo, set in GetElementFromElementFactory for the cases where the repeater propagates it) and clear it in ClearElementToElementFactory, so recycled-but-unused elements do not retain stale data.
Potential consequences of the gap
- Lifetime / memory: a pooled element roots the removed item's entire object graph through its
DataContextuntil the element is reused or the repeater is unloaded. If no later item resolves to the same template, the removed item is never collected. - Live bindings against removed data: bindings on the pooled element keep observing the removed item (
INotifyPropertyChangedsubscriptions stay active). Property changes on data the user already removed still run binding updates on invisible elements — wasted work, and element state (visual states, attached-property drivers, animations) can be mutated while pooled. - Crash class WinUI explicitly fixed: the WinUI comment states the clear exists "to prevent crashes" — e.g. handlers reacting to stale data touching disposed models. Uno remains exposed to that class.
- Reuse semantics differ: on WinUI, reuse transitions the DataContext null → new, so
DataContextChangedand binding refresh are guaranteed. On Uno it transitions old → new; if the new value equals the old (or is the same reference), change-driven mechanisms do not re-fire — the "true→true doesn't re-fire" trap documented in the ItemsRepeater: animated content (ProgressRing/AnimatedVisualPlayer) in recycled elements keeps rendering — render loop never idles (high CPU on Skia/WASM) #23446 workaround notes. - App-observable parity difference:
DataContextChangedfires on recycle on WinUI but not on Uno, so cleanup logic written against WinUI behaves differently on Uno.
Note: this gap is orthogonal to the render-loop issue #23446 / PR #23447. Measured on real WinUI, the ring's {Binding}-driven IsActive keeps its last value after the DataContext is cleared, so porting the clear would not have fixed that bug.
How to reproduce it (as minimally and precisely as possible) 🔬
- Run the
ItemsRepeater_RecycledSpinnersample (added in fix(skia): suspend recycle-pooled element visuals #23447) on any Uno target and on the WinAppSDK head. - Press "Remove spinner item".
- Compare the mechanism readout:
dataContextUnchanged=Trueon Uno,Falseon WinUI.
Or minimally: two DataTemplates in an ItemsRepeater, remove an item whose template no other item uses, and inspect the recycled element's DataContext (obtained via TryGetElement before removal).
Workaround 🛠️
Handle ItemsRepeater.ElementClearing and perform cleanup there (e.g. clear the DataContext manually or detach handlers/animations), mirroring the documented WinUI contract.
Renderer 🎨
Skia, Native (the Repeater code is shared — the gap is renderer-independent)
Affected platforms 📱💻🖥️
All targets
Uno.Sdk version (and other relevant versions) 📦
Current master (03226da); behavior present in all released versions (the port predates the upstream MustClearDataContext change).
Anything else we need to know? 💬
Discovered while validating #23446 with PR #23447. Aligning this is a WinUI-source-aligned change (ports ViewManager.cpp#L144-L167 and the flag plumbing on VirtualizationInfo). Any fix should include a runtime test asserting the pooled element's DataContext is cleared on recycle and re-set on reuse — including the same-value reuse case (consequence 4).
Activity
Jen-Uno commentedon Sep 30, 2026
QA: closing out without a manual pass. This was fixed by #23406, the same PR as #22908, and that PR ships with automated tests (
ItemsViewSummaryPage.xaml,AspectRatioRespectingControl.cs,FlowLayoutCollectionChangeTests.mux.csand 8 more) that exercise the change.If you still see this behaviour on a build that includes that PR, please reopen or comment here.