Repository navigation
Description
Summary
On the Skia render path (Desktop and WebAssembly), an ItemsRepeater keeps a recycled element parented in the visual tree until it is reused. If that element hosts continuously-animating content — e.g. an indeterminate ProgressRing (which is an AnimatedVisualPlayer + Lottie) — the animation keeps running on the recycled-but-still-parented element. The Skia render loop therefore never goes idle: the whole canvas repaints every frame at ~100% of a CPU core, even though nothing animated is visible on screen.
This happens whenever a list item with active animated content is removed/replaced and no later item reuses its element (for example, the replacement item resolves to a different DataTemplate).
Environment
- Uno Platform 6.7 (also present on current
master). - .NET 10.
- Reproduces on the Skia render path: Desktop (X11 / macOS / Windows Skia) and WebAssembly (Skia).
Root cause
- Recycled elements stay parented.
RecyclePool.PutElementCoreadds the element to the pool without detaching it from its parent. It is only removed from the parent later, inRecyclePool.TryGetElementCore, when the element is reused for another item. → If it is never reused, it stays a child of theItemsRepeaterindefinitely.src/Uno.UI/UI/Xaml/Controls/Repeater/RecyclePool.cs—PutElementCore(no detach) vsTryGetElementCore(detaches on reuse).
- DataContext is not cleared on recycle (Uno-specific divergence). On Uno, it is set on prepare (
ViewManager→elementAsFE.DataContext = elementDataContext) and only overwritten on reuse. A recycled element keeps its stale DataContext, so a data-boundProgressRing.IsActivestaystrueand noDataContextChangedfires. Current WinUI behaves differently:ViewManager::ClearElementToElementFactorynulls the DataContext on recycle when the repeater set it (MustClearDataContext); Uno's Repeater port predates that change. This divergence is not what makes the bug Skia-specific, though: measured on real WinUI, the nulled DataContext leaves the{Binding}-drivenIsActiveat its last value (true) — the pooled ring keeps animating there too. - The animation self-schedules while parented + active. For the indeterminate
ProgressRingthe Skia source (src/AddIns/Uno.UI.Lottie/LottieVisualSource.Skottie.cs) re-invalidates from its ownRender()every frame while playing (if (_stopwatch.IsRunning) _skCanvasElement?.Invalidate();), and the looped animation restarts the stopwatch forever. Because the recycled element is still in the visual tree and the ring is still active, it keeps invalidating the canvas → the render loop runs at full frame rate continuously. ElementClearingdoes fire on the granular clear path, but the framework does nothing to stop/pause animations in the cleared element, and (per 1–2) the element is not unloaded — and on Uno its DataContext is not cleared either.
Net effect: a removed item's animated element is left parented and animating forever — high idle CPU, no visible animation.
Minimal reproduction
A minimal UI with two DataTemplates (so the spinner element is recycled but not reused). On Skia desktop or WASM:
MainPage.xaml
<Page x:Class="RepeaterSpinnerRepro.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:local="using:RepeaterSpinnerRepro">
<Page.Resources>
<DataTemplate x:Key="SpinnerTemplate">
<!-- Active indeterminate spinner. -->
<muxc:ProgressRing IsActive="True" Width="24" Height="24" Margin="8" />
</DataTemplate>
<DataTemplate x:Key="TextTemplate">
<TextBlock Text="{Binding Title}" Margin="8" />
</DataTemplate>
<local:ReproTemplateSelector x:Key="Selector"
SpinnerTemplate="{StaticResource SpinnerTemplate}"
TextTemplate="{StaticResource TextTemplate}" />
</Page.Resources>
<StackPanel Padding="24" Spacing="12">
<Button Content="Remove the spinner item" Click="OnRemoveSpinner" />
<ScrollViewer Height="200">
<muxc:ItemsRepeater x:Name="Repeater"
ItemTemplate="{StaticResource Selector}" />
</ScrollViewer>
</StackPanel>
</Page>MainPage.xaml.cs
using System.Collections.ObjectModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace RepeaterSpinnerRepro;
public sealed record Item(string Title, bool IsSpinner);
public sealed partial class MainPage : Page
{
private readonly ObservableCollection<Item> _items = new()
{
new Item("a plain row", IsSpinner: false), // TextTemplate (a different template)
new Item("the spinner", IsSpinner: true), // SpinnerTemplate (active ProgressRing)
};
public MainPage()
{
InitializeComponent();
Repeater.ItemsSource = _items;
}
private void OnRemoveSpinner(object sender, RoutedEventArgs e)
{
// Remove the spinner item. Its element is recycled, but nothing reuses it
// (the only remaining item uses TextTemplate), so it stays parented + animating.
var spinner = _items.FirstOrDefault(i => i.IsSpinner);
if (spinner is not null) _items.Remove(spinner);
}
}
public sealed class ReproTemplateSelector : DataTemplateSelector
{
public DataTemplate? SpinnerTemplate { get; set; }
public DataTemplate? TextTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item)
=> (item is Item { IsSpinner: true } ? SpinnerTemplate : TextTemplate)!;
}Steps
- Run on Skia desktop or WebAssembly. Both rows render; the spinner animates.
- Click “Remove the spinner item.” The spinner disappears from view (only the plain row remains).
- Observe CPU: it stays pegged at ~100% of one core indefinitely, with no visible spinner.
- WASM: DevTools → Rendering → Paint flashing shows the whole canvas repainting every frame; the Performance monitor shows continuous CPU.
- Desktop: a system CPU monitor (or
dotnet-counters monitor) shows sustained high CPU; the render loop never idles.
To confirm the mechanism programmatically: capture the realized spinner element via Repeater.TryGetElement(index) before removal, then after removal observe that it is still parented (VisualTreeHelper.GetParent(...) != null), its DataContext is unchanged on Uno (no DataContextChanged; on real WinUI the DataContext is cleared on recycle — see root cause 2), and the nested ProgressRing.IsActive is still true (measured on both Uno/Skia and WinUI).
Contrast: if the replacement item uses the same template (so the element is reused), the DataContext updates on reuse and the spinner deactivates — no leak. The bug only manifests when a recycled element is not reused.
What is (and is not) Uno's to fix
Of the behaviors described above, the first is WinUI-parity by design and should NOT change; the second is a real divergence but orthogonal to this bug:
- Recycled elements staying parented (
RecyclePool.PutElementCorenot detaching) matches WinUI's MUX implementation; same-owner elements are deliberately kept attached "so that we don't incur the enter/leave cost during recycling". Detaching on recycle would regress recycle performance and diverge from WinUI. - Stale DataContext on pooled elements turns out to be Uno-specific, not parity: current WinUI clears the DataContext on recycle when it set it (
MustClearDataContext); Uno's port predates that change. Porting the clear is a separate parity work item (tracked in ItemsRepeater: DataContext not cleared on recycle (missing WinUI MustClearDataContext parity) #23624) — but measurably not a fix for this bug: on real WinUI the ring's boundIsActivekeeps its last value (true) after the clear, so the pooled spinner keeps animating there as well. Either way, data bindings are not a viable shutdown mechanism for a recycled element; the documented WinUI contract remains that the app stops animations inItemsRepeater.ElementClearing, and that contract holds for Uno too.
The Uno-owned defect is the render-loop cost model for animated visuals that are not effectively rendered:
- On WinUI, forgetting the
ElementClearinghygiene is near-free — composition animations run on the compositor with dirty-region rendering, so an invisible animated visual does not pin the UI thread. - On the Skia path, the same omission permanently pins a CPU core with full-canvas repaints from content that contributes zero visible pixels (and on WebAssembly that is effectively fatal). A render loop that can be pinned forever by a non-rendered animation is a platform defect regardless of app hygiene.
Expected
- Render layer (the fix): a recycle-pooled element that stays parented should not keep the render loop awake. Its visual should be excluded from composition while it sits in the pool, and restored when it is reused — so continuously-animating content it hosts cannot keep invalidating the canvas once its item has been removed.
- Ideally, partial invalidation: one small animating visual should dirty its own region, not force a whole-canvas repaint every frame.
- Docs: the
ElementClearingstop-animations pattern should be documented as a workaround on Skia targets forItemsRepeatercontent hosting continuous animations on versions without the fix, since the failure mode there is catastrophic rather than benign.
Actual
The recycled element remains parented with its ProgressRing active; the Skia render loop runs at full frame rate continuously (~100% of a core), invisibly.
Notes / downstream workaround
Consumers can subscribe to ItemsRepeater.ElementClearing and stop animations in the cleared element (deactivate any ProgressRing, and/or collapse the element so it leaves the render pass), restoring on ElementPrepared. Two practical traps for anyone applying this workaround:
- A plain
IsActive = falsewrite on the cleared element can be overridden while the stale DataContext keeps a visual state / attached-property driver asserting "active" — collapsing the element is the robust part of the workaround. - The restore on
ElementPreparedmust re-drive the animation state from the new DataContext, not just restore visibility: value-change-driven mechanisms (bindings, attached-property walks,StateTriggers) do not re-fire when the new item produces the same values as the stale one (true→true), which otherwise leaves a visible row with a permanently stopped spinner.
Activity
DerekRaven commentedon Jul 2, 2026
WinUI vs Skia: same framework behavior, different consequences
To clarify why this issue is Skia-specific even though the
ItemsRepeater/RecyclePoolbehavior is identical to WinUI, here is the exact distinction, with references to the WinUI sources (pinned atmicrosoft/microsoft-ui-xaml@d4aeb08).What is identical in WinUI (framework parity)
The recycled element stays parented and its animation stays active in WinUI too — that part is not Uno divergence:
RecyclePool::PutElementCoredoes not detach, hide, or stop anything. It only records the element in the pool: RecyclePool.cpp#L43-L66. The element is removed from its parent only later, inTryGetElementCore, and only when it is reused under a different owner: RecyclePool.cpp#L99-L117. If it is never reused, it stays a child of theItemsRepeaterindefinitely — in WinUI as well.WinUI's only mitigation is a layout-level one:
ItemsRepeater::ArrangeOverridearranges pool-owned children at(-10000, -10000)with size 0 — "Toss it away. And arrange it with size 0 so that XYFocus won't use it.": ItemsRepeater.cpp#L195-L204 (constant at ItemsRepeater.cpp#L23). Note the stated intent: it exists for XYFocus, not to stop rendering or animations. This code is already faithfully ported to Uno: ItemsRepeater.cs#L322-L331.The
ProgressRinganimation keeps playing while pooled in WinUI. WhenIsActiveis true,ProgressRingstarts a loopedAnimatedVisualPlayerplay —player.PlayAsync(0, 1, /*looped*/ true): ProgressRing.cpp#L329-L341. Nothing inRecyclePool,ViewManager, orProgressRingpauses it when the host element is recycled — the ring in the pool is still "spinning" in WinUI, exactly as on Skia.One measured divergence: current WinUI clears the DataContext on recycle
Running the #23447 repro sample on the WinAppSDK head (real WinUI) reports
stillParented=True / dataContextUnchanged=False / ringIsActive=Trueafter the spinner item is removed. TheFalsecomes fromViewManager::ClearElementToElementFactory, which nulls the DataContext when the repeater was the one that set it (theMustClearDataContextflag): ViewManager.cpp#L144-L167, set on prepare at ViewManager.cpp#L805-L844. Uno's Repeater port predates this MUX change and never clears the DataContext — a real parity gap (tracked in #23624), but orthogonal to this bug: with the DataContext nulled, the{Binding}-drivenProgressRing.IsActivesimply keeps its last value (true), so the pooled ring keeps animating on WinUI as well — measured, not just inferred from the sources above.Why the consequences differ
The divergence is entirely in how the animation is driven and what an invisible animating visual costs:
WinUI: the
AnimatedVisualPlayerLottie is a composition (independent) animation — its progress is advanced by anAnimationControlleron the composition engine's clock, off the XAML UI thread. A zero-size visual parked at (-10000, -10000) produces no pixels, wakes no per-frame UI-thread work, and the XAML render loop stays idle. The animation "runs" as retained-mode compositor state at effectively zero cost.Uno Skia: the Lottie player is paint-driven. Each
Render()pass seeks the animation and schedules the next frame by invalidating its canvas element again: LottieVisualSource.Skottie.cs#L302 → #L345-L351.Render()has no size or on-screen early-out, and the Skia compositor culls a subtree only onOpacity == 0/IsVisible == false(Visual.skia.cs#L312) — not on being off-screen or zero-sized. So the pooled ring keeps getting painted, each paint re-invalidates, and the render loop never idles: full-canvas repaints at frame rate, ~100% of one core, indefinitely.Implication
There is no WinUI source to align with for a fix: the one relevant mechanism WinUI has (the size-0 off-screen arrange) is already ported and running, and it cannot help because on Skia the cost comes from the paint-driven invalidation loop, not from visible pixels. Preventing the pooled element from participating in composition (or, longer-term, teaching the Skia compositor/Lottie player to stop self-invalidating when not effectively painted) is inherently renderer-level, Uno-specific work.
This has now been measured with the same scenario on both frameworks (the repro sample in #23447 builds for the WinAppSDK head and uses only public API for its readouts): after removal, WinUI reports
stillParented=True / dataContextUnchanged=False / ringIsActive=Truewith the app near idle, versusTrue / True / Trueand ~100% of a core, indefinitely, on Skia. The key readout isringIsActive=Trueon both: even after WinUI clears the DataContext, the pooled ring keeps animating — WinUI just doesn't pay for it. So even the strongest available "align with WinUI sources" move (porting theMustClearDataContextclear) demonstrably would not fix this bug.Edited: this comment originally predicted
dataContextUnchanged=Trueon WinUI; an actual WinAppSDK run measuredTrue / False / True. The DataContext section above documents the divergence (MustClearDataContext), which Uno's port predates.fix(skia): suspend recycle-pooled element visuals
github-actions commentedon Nov 10, 2026
This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.