Skip to content

fix: Release subscriptions of never-loaded repeaters and collected bindings - #26115

Merged
Xiaoy312 merged 35 commits into
masterfrom
dev/xygu/20261105/repeater-binding-leaks
Nov 6, 2026
Merged

Xiaoy312 merged 35 commits into
masterfrom
dev/xygu/20261105/repeater-binding-leaks

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes unoplatform/kahua-private#566

PR Type:

🐞 Bugfix

What changed? 🚀

Two leaks in a common app pattern: a view model kept for the whole session, with views rebuilt on every visit. In both, a long-lived source keeps strong references to subscribers that should have gone away with the view.

The first three commits are the reporter's patches, ported to master. They are kept as written, and every change on top of them is a separate commit.

1. A never-loaded ItemsRepeater stays alive

items source (a view model's collection)
 → ItemsSourceView       (source.CollectionChanged handler)
 → ItemsRepeater         (ItemsSourceView.CollectionChanged handler)
 → everything the repeater references (its template, its page, ...)

WinUI holds no reference at either hop: InspectingDataSource and ItemsRepeater both subscribe with raw-this delegates. Uno removed the repeater's handler on Unloaded, but a repeater that never loads never unloads. For example, the content of a Flyout is created and bound even if the flyout is never opened. The ~ItemsSourceView finalizer, meant to remove the source subscription, could never run either, because the subscription itself kept the view reachable.

  • ItemsSourceView subscribes through a forwarder that holds the view weakly. The view keeps a subscription object whose finalizer removes the forwarder once the view is collected; ~ItemsSourceView is gone.
  • ItemsRepeater subscribes to its ItemsSourceView with a handler that holds the repeater weakly. The handler is removed the same way once the repeater is collected, not only on the view's next raise.
  • TransitionManager had the same problem with a shared ItemTransitionProvider: its TransitionCompleted handler is now weak too. Unloaded still removes it right away.

Behavior change (no API change): an ItemsSourceView is no longer kept alive by its source. Code that creates one, subscribes to CollectionChanged, then drops its own reference stops receiving events once the view is collected. This matches WinUI, and a new test checks it on both Uno and native WinUI. Every in-repo consumer keeps a reference to its view (ItemsView, RadioButtons, BreadcrumbBar, SelectionNode, TreeViewNode, NavigationView). The throwaway views NavigationView creates to inspect its items used to leave a permanent handler on the source; they no longer do.

2. {Binding} leaves its handlers on the source

BindingPath added a PropertyChanged handler that holds the binding weakly, but removed it only when the binding was disposed. Bindings of a view that is simply dropped are never disposed. So a long-lived source accumulated one handler, with its weak references and GC handles, per element ever bound to it. The reporter measured 694 handlers on one view model after 11 rounds.

On WinUI, the subscription goes away when the binding expression is destroyed. This PR is the .NET counterpart: the subscription the binding keeps is an object whose finalizer removes the handler once the binding is collected, even if the source never raises again. Dispose behaves as before and suppresses the finalizer, which is the path recycled list items take when their DataContext changes. Bindings with an indexer path ({Binding Items[0]}) also subscribe to the collection's CollectionChanged; that handler captured the binding strongly, and now gets the same treatment.

Shared cleanup

All of the above, and the CanExecuteChanged subscription of ButtonBase / MenuFlyoutItem (#25965), now use one helper, WeakSourceSubscription:

  • The source is held weakly, through a raw weak GCHandle. A source that dies together with its subscriber (a page and its view model) is collected at once and needs no removal. The reporter's version, and fix: Subscribe to Command.CanExecuteChanged weakly #25965's command subscription, held the source strongly until the queued removal ran; new tests cover both.
  • Removals run on the UI thread, since sources aren't required to be thread-safe. SubscriptionCleanup queues them from finalizers and drains them at Low priority, in batches of at most 256 removals or 3 ms, with a single dispatcher item at a time.
  • Failures are logged, never thrown, from the finalizer path and from Dispose, and the message names the source's type. This is new for a binding's Dispose, which used to throw if the source's remove accessor did.

Why finalizers

A dropped page has no deterministic teardown point: content that never loaded is never unloaded, and nothing disposes its bindings. WinUI frees its subscriptions when the reference count of the binding expression or control drops to zero; in .NET, that moment is only observable through finalization. The reviewer's alternative, one weak fan-out handler per source, would make the removals much cheaper (see below), but still needs the same trigger to prune dead entries. It's tracked in #26127.

Cost

Measured on Skia desktop (Win32), this PR against its merge-base:

  • Recycling: 20 bindings whose DataContext is swapped 10,000 times take about 10-15% longer (one finalizable object per subscription), with slightly fewer bytes allocated (33.6 vs 34.8 KB per swap).
  • Navigation: visiting a 3000-binding page 20 times on one long-lived view model, with a full GC between visits, costs the same to build. The queued removals then take about 72 ms of UI-thread time per visit, in batches of at most 3 ms. On the merge-base, 60,000 dead handlers are left on the view model and a raise takes 4.3 ms; with this PR, none are left.
  • Worst case: removing n dead handlers from one source costs O(n²), because every -= copies the event's invocation list. With 20 such pages collected before any removal runs (90,000 pending on one view model), the removals take about 60 s of UI-thread CPU, still in 3 ms batches. The per-source fan-out in Subscribe {Binding} to a source through one shared handler per source #26127 would remove this cost.

Validation

  • Runtime, Skia desktop (Win32):
    • The new tests fail before their fix, and pass after it: never-loaded repeaters (the reporter's), stale binding handlers, sources dropped with their subscriber (bindings, items sources, commands), dead repeaters' handlers on a shared view, a shared transition provider.
    • The leak classes (Given_ItemsRepeater_Leak, Given_BindingStaleHandlers, Given_CommandCanExecuteChanged, Given_BindingMemoryLeak) pass 10 iterations in a row with a single attempt each.
    • Regression run: 973 passed, 0 failed, 66 skipped ([Ignore]). It covers the Repeater, ItemsView and NavigationView suites (Uno and MUX), the Data and binding suites, Given_UIElement, Given_FrameworkElement, Given_ItemsControl, Given_ContentControl, Given_Button, Given_MenuFlyoutItem and Given_AppBarButton.
  • Runtime, native WinUI (WinAppSDK): the leak tests now run there in CI, except those that count the handlers of collected bindings: WinUI removes them on its own schedule, which made them fail within a few iterations. Each remaining exclusion states its reason. Measured with 10 then 30 iterations: the repeater leak tests, When_Binding_Cleared_Then_Handler_Removed, the dropped-together tests and the ItemsSourceView behavior-change test pass every time.
    • A final run of the four leak classes, 10 iterations with a single attempt each: all 26 enabled cases pass, including the shared transition-provider test.
  • CI, build 244099 (before this round): the new leak tests passed on WASM, iOS, Android, Linux (X11, framebuffer, WebGPU), macOS and Windows.
  • Unit tests: Uno.UI.UnitTests has no new failures. The 13 Given_Calendar failures are the existing time-zone baseline.
  • Reporter's repro, against this build: closed views still alive and subscribers left go from 10 / 30 / 10 to 0 / 0 / 0. Re-run after this round: still 0 / 0 / 0.
  • Compile: strict desktop build (analyzers on), the WinAppSDK head, and dotnet format whitespace are clean.

Follow-ups

Backports to the stable branches will follow.

PR Checklist ✅

🤖 Generated with Claude Code

jbourque-kahua and others added 13 commits November 5, 2026 11:24
…er alive

WinUI's InspectingDataSource and ItemsRepeater subscribe with raw-'this'
delegates, which hold no reference to the subscriber. Uno's ports used
ordinary handlers, so an items source that outlives a repeater (a view
model's collection) kept the ItemsSourceView alive, and through it the
repeater and everything it references.

Unloaded removes the repeater's handler, but a repeater that never loads
never unloads: the content of a flyout that is never opened is created
and bound anyway, and kept the page that declares it alive. The
ItemsSourceView finalizer meant to remove the source subscription could
never run either, since the subscription itself rooted the view.

- ItemsSourceView subscribes through a small subscription object that
  holds the view weakly. The view's finalizer removes it from the source
  on the UI thread, as WeakCanExecuteChangedSubscription does, since the
  source isn't required to be thread-safe.
- ItemsRepeater subscribes to its ItemsSourceView through a handler that
  holds the repeater weakly and removes itself once the repeater is gone.

Behavior change: an ItemsSourceView is no longer kept alive by its
source. Code that creates one, subscribes to its CollectionChanged and
keeps no reference to it stops receiving events once it is collected,
as on WinUI. Keep a reference to the view for as long as it is needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A {Binding} subscribes to its source's PropertyChanged with a handler
that holds the binding only weakly, and removes it when the binding is
disposed. When the bound element is dropped without its bindings being
cleared, the binding is collected but the handler stays on the source.
A source that outlives its views, like a view model kept while its
views are rebuilt, then accumulates one handler (with its weak
references and GC handles) per element ever bound to it, without bound.

The subscription returned to the binding is now an object whose
finalizer removes the handler once the binding is gone, without
waiting for the source to raise. The removal is queued on the UI
thread, since the source isn't required to be thread-safe, as
WeakCanExecuteChangedSubscription does for commands.

The subscription holds its source strongly so that the finalizer can
still reach it: the pooled weak references may already be finalized by
then. This only links the binding to its source, which the bound
element's DataContext already does, and the link is dropped on Dispose.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WeakCanExecuteChangedSubscription, ItemsSourceView and the binding
PropertyChanged subscription each queued the removal of a subscription
on the UI thread from a finalizer, guarded against throwing, and logged
failures. SubscriptionCleanup now does this in one place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
master keeps the repeater and binding runtime tests under
Microsoft/UI/Xaml, next to Given_ItemsRepeater and
Given_BindingMemoryLeak. The namespaces already match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The DataTemplate(Func<>) constructor the 6.8 test used is gone on
master; build the item template with DataTemplate(owner, factory).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The subscription that removes a collected binding's PropertyChanged
handler held its source strongly, so that its finalizer could still
reach it. In the common case, a page and its view model dropped
together, this kept the view model alive through finalization and
until the queued removal ran on the UI thread, although the removal
was pointless: both sides were dead. master freed it in one GC.

The source is now held through a raw weak GCHandle. Unlike a pooled
ManagedWeakReference, it has no finalizer of its own that could run
first, and it is cleared before finalizers run, so a source that died
with the binding needs no removal at all. A live source, the leak this
subscription exists for, is still unsubscribed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A binding whose path indexes into a collection ({Binding Items[0]})
also listens to the collection's CollectionChanged. That handler
captured the binding item strongly and was only removed on Dispose,
so a collection that outlives its views kept every binding ever made
on it alive, along with their PropertyChanged subscriptions, whose
cleanup then never ran.

The handler now holds the binding item weakly, and the subscription is
removed once the binding is collected, like the PropertyChanged one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each subscription removed from a finalizer queued its own dispatcher
item at Normal priority. Collecting a page with thousands of bindings
then queued thousands of items, which delayed the next frame until
they all ran.

Removals now go into one queue, drained at Low priority in batches of
256 by a single dispatcher item.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The source subscription is also referenced by its view, so what
matters is that it holds the view weakly. The file header now lists
the weak data-source subscription, and notes when a dead repeater's
handler goes away.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The description passed to SubscriptionCleanup.Run was interpolated on
every Dispose, although it's only used if the removal fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The repeater, binding and CanExecuteChanged leak tests each had their
own copy of the helper that collects and pumps the dispatcher until
finalizer-queued removals have run. It now lives in LeakTestHelper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- an ItemsSourceView nobody references releases its subscription for
  each kind of observable source (INotifyCollectionChanged,
  IObservableVector<object> and Uno's untyped IObservableVector);
- a raise to collected repeaters doesn't keep their subscriptions;
- a nested binding path releases the handler of every segment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
They pass there, and they count real .NET subscribers and objects, so
CI can check that Uno releases the same subscriptions WinUI does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

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

@Xiaoy312

Xiaoy312 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport release/stable/6.7 servicing/6.8

@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7 servicing/6.8

✅ Backports have been created

Details

Cherry-pick of 0a44387 has failed:

On branch mergify/bp/release/stable/6.7/pr-26115
Your branch is up to date with 'origin/release/stable/6.7'.

You are currently cherry-picking commit 0a44387.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs
	modified:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsSourceView.Impl.cs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsRepeater.mux.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsRepeater.uno.cs

Cherry-pick of 69d2696 has failed:

On branch mergify/bp/release/stable/6.7/pr-26115
Your branch is ahead of 'origin/release/stable/6.7' by 3 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 69d2696.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	deleted:    src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_BindingStaleHandlers.cs

Cherry-pick of f2e148b has failed:

On branch mergify/bp/release/stable/6.7/pr-26115
Your branch is ahead of 'origin/release/stable/6.7' by 21 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit f2e148b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_CommandCanExecuteChanged.cs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of 0a44387 has failed:

On branch mergify/bp/servicing/6.8/pr-26115
Your branch is up to date with 'origin/servicing/6.8'.

You are currently cherry-picking commit 0a44387.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs
	modified:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsSourceView.Impl.cs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsRepeater.mux.cs
	deleted by us:   src/Uno.UI/UI/Xaml/Controls/Repeater/ItemsRepeater.uno.cs

Cherry-pick of 69d2696 has failed:

On branch mergify/bp/servicing/6.8/pr-26115
Your branch is ahead of 'origin/servicing/6.8' by 3 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit 69d2696.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	deleted:    src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_BindingStaleHandlers.cs

Cherry-pick of f2e148b has failed:

On branch mergify/bp/servicing/6.8/pr-26115
Your branch is ahead of 'origin/servicing/6.8' by 21 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit f2e148b.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/Given_ItemsRepeater_Leak.cs

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_CommandCanExecuteChanged.cs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • AppBarButtonWithIconTest.png
    • ApplicationViewMode.png-dark
    • AppWindowClosing.png-dark
    • AppWindowPresenters.png
    • Arrange_Performance01.png
    • AuthenticationBroker_Cancel.png
    • AutoBorderStretchwithtopmargin.png-dark
    • AutomationProperties_Name.png-dark
    • AutomationProperties_Name.png
    • AutoSuggestBox_Description.png-dark
    • AutoSuggestBox_Description.png
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • BasicThemeResources.png-dark
    • BasicThemeResources.png
    • BitmapIcon_Generic.png-dark
    • BitmapIcon_Generic.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBar_KeyBoard.png-dark
    • Application_DispatcherShutdownMode.png
    • AppWindowPresenters.png-dark
    • AppXamlDefinedResources.png
    • Attributed_text_FontSize_Changing.png-dark
    • AuthenticationBroker_Cancel.png-dark
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BackGesture.png-dark
    • BackGesture.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • Battery.png-dark
    • Battery.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png

@ajpinedam ajpinedam 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.

Follow-ups from a deeper pass. The high and medium items are inline; the lower-severity ones are in a separate comment.

For context, from build 244099: the new leak tests ran on WASM, iOS, Android, Linux (X11, framebuffer, WebGPU), macOS and Windows with no failures. The iOS result XML shows each of them as a real pass, including When_Element_And_Source_Dropped_Together_Then_Source_Collected_Without_Dispatcher (not Inconclusive). The red Android shard 3 is Given_InputPane.When_Focus_Moves_While_Occluded_Then_New_Field_Brought_Above_Occlusion, which this PR doesn't touch.

Comment thread src/Uno.UI/DataBinding/BindingPath.cs Resolved
Comment thread src/Uno.UI/DataBinding/BindingPath.cs Resolved
@ajpinedam

Copy link
Copy Markdown
Contributor

Lower-severity items from the same pass; none of these blocks the PR.

  1. The no-yield preconditions are hard asserts (Given_ItemsRepeater_Leak.cs:135,195, Given_BindingStaleHandlers.cs:61). LeakTestHelper says Browser, Linux, iOS and Android need a yield before weak references clear, and Given_CommandCanExecuteChanged uses Assert.Inconclusive for the same step. CI is green for all of them on this build, so this is only a robustness note.
  2. #if HAS_UNO wraps a whole [TestMethod] (Given_ItemsRepeater_Leak.cs:60-98). The runtime-test guidelines ask for attributes here, because the #if breaks test discovery. The method already has PlatformCondition(Exclude, NativeWinUI), so the #if could move into CreateScreenWithFlyout.
  3. All 10 of the reporter's tests are excluded on NativeWinUI, while the description says only two fail there. The other eight could run on WinUI.
  4. The checkbox contradicts the description. "NO breaking changes" is ticked, but the description declares the ItemsSourceView lifetime change. Worth making them consistent, and adding a one-line note to the release notes and the backport PRs.
  5. SubscriptionCleanup failure handling (SubscriptionCleanup.cs:43-106):
    • "Failed to schedule the removal of …" reads like a leak, although the item stays queued, and it logs one Error per item.
    • RunBatch doesn't re-arm in a finally if logging throws.
    • Nothing reports how many removals were drained or are still pending. A Debug line in RunBatch, behind IsEnabled, would tell a late removal from a leak.
  6. Capture rules live only in comments. "must not capture 'notify'" (BindingPath.cs:533) and "must not capture 'this'" (ItemsSourceView.Impl.cs:163) aren't enforced. static lambdas with explicit state would make a capture a compile error.
  7. Port hygiene in ItemsSourceView.Impl.cs. The ported UnListenToCollectionChanges was inlined into the finalizer, and SourceSubscription sits in the MUX file. An .uno.cs partial that keeps the ported method name would match the repeater side. Also, ItemsRepeater.uno.cs:90-91 repeats the file-header bullet.
  8. Test duplication.
    • LeakTestHelper.CollectAsync is a copy of Given_BindingMemoryLeak.AssertCollectedAsync, which could use it instead.
    • The no-yield GC loop appears 4 times.
    • When_Repeater_Collected_Then_Raising_CollectionChanged_Is_Safe is covered by When_Repeater_Collected_And_Source_Raised_Then_Subscription_Removed.
  9. Small allocations. The finalizer at BindingPath.cs:584-585 allocates a closure each time it runs, and WeakCanExecuteChangedSubscription now allocates one on every Dispose, where it used to call -= directly. Passing the source and an Action<object> through PendingRemoval would avoid both.
  10. Another never-loaded path remains (pre-existing, TransitionManager.mux.cs:35). A never-loaded repeater with a shared ItemTransitionProvider subscribes to it strongly and only detaches on Unloaded.

Xiaoy312 and others added 8 commits November 5, 2026 18:49
Measured on native WinUI with 10 then 30 iterations, one attempt each:

- The repeater leak tests and When_Binding_Cleared_Then_Handler_Removed
  pass every time, so the reporter's ones now run on WinUI too.
- Tests that count the handlers of collected bindings fail within a few
  iterations: WinUI removes them on its own schedule, sometimes after the
  test's collection window. The indexer and nested-path tests are excluded
  again, and the reporter's two such tests stay excluded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test added in 0d9f987 repeated the reporter's raise-safety test and
only added a subscriber-count assertion. That assertion now ends the
reporter's test, renamed to say what it checks, and the copy is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o.cs

SourceSubscription is Uno-specific: keep it out of the file ported from
WinUI. No change in behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It was private to BindingPath: make it a shared helper, taking the type to
log failures under, so that other weak subscriptions can use it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The callbacks are now static lambdas that get their state explicitly, so
capturing the source (which would keep it alive) is a compile error rather
than a rule stated in a comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A removal copies the source's whole handler list, so 256 removals from a
source with thousands of stale handlers could make one long main-thread
task. A batch now also stops after 3 ms and reschedules the rest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

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

Xiaoy312 and others added 3 commits November 5, 2026 22:26
An #if around a [TestMethod] hides it from test discovery: move it into
the helper that uses the Uno-only DataTemplate(owner, factory). The test
is still excluded on native WinUI by its PlatformCondition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A repeater that never loads never unloads to detach from its
ItemTransitionProvider. It fails before the next fix: the provider's
TransitionCompleted handler held the repeater strongly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ters

TransitionManager subscribed to its provider's TransitionCompleted with a
strong delegate, removed only on Unloaded, so a provider that outlives a
never-loaded repeater (e.g. a shared one) kept it alive. WinUI subscribes
with a raw-'this' delegate, holding no reference.

The handler now holds the manager weakly, and the manager keeps a
WeakSourceSubscription, whose finalizer removes the handler once the
repeater is collected. Unloaded still removes it right away.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedIconPage.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png-dark
    • Application_DispatcherShutdownMode.png
    • AppWindowPositionAndSize.png
    • AppXamlDefinedResources.png
    • Attributed_text_FontSize_Changing.png-dark
    • AuthenticationBroker_Cancel.png
    • AuthenticationBroker_Demo.png-dark
    • AutomationProperties_Landmark.png
    • AutomationProperties_Name.png-dark
    • AutoSuggestBox_BitmapIcon.png-dark
    • AutoSuggestBox_BitmapIcon.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BorderBottomwithmargins.png-dark
    • BorderBottomwithmargins.png
    • BorderLeftwithmargins.png-dark
    • BorderLeftwithmargins.png
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png-dark
    • Accessibility_ScreenReader.png
    • AnimatedVisualsTestbedPage.png
    • AppBar_KeyBoard.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • Application_DispatcherShutdownMode.png-dark
    • AppWindowFeatures.png-dark
    • AppWindowPositionAndSize.png
    • AppWindowTitleBar Properties.png
    • Arrange_Performance01.png
    • AppXamlDefinedResources.png-dark
    • AuthenticationBroker_Cancel.png-dark
    • Attributed_text_Simple.png
    • AutoBorderStretchwithrightmargin.png
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_Landmark.png-dark
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationProperties_Landmark.png
    • AutomationPropertiesExtensions_Role.png

@Xiaoy312

Xiaoy312 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Re: the lower-severity items

Thanks, all addressed:

  1. No-yield asserts: my tests use Assert.Inconclusive (the redundant one was folded away, see 8); the reporter's keep their hard asserts, which passed on every CI target.
  2. cd3b286: the #if now wraps the body of CreateScreenWithFlyout, so the test is discoverable everywhere and excluded on WinUI by its PlatformCondition.
  3. d98d776 / 7d9cbf7: measured on native WinUI with 10 then 30 iterations. The reporter's repeater tests and When_Binding_Cleared_Then_Handler_Removed now run there; the tests that count handlers of collected bindings stay excluded (WinUI removes them on its own schedule, so they fail within a few iterations), and two of mine were excluded for the same reason. Each exclusion states its reason.
  4. Description updated: no API change, one behavior change matching WinUI; the backport PRs will repeat it.
  5. 1793f56: a schedule failure is a Warning that says the removal stays queued (only a failure to queue is an Error); the batch reschedules in a finally; a Debug line reports removed / still-queued counts.
  6. f53ad2b: the callbacks are static lambdas that get their state explicitly, so capturing the source is a compile error.
  7. a74be11: SourceSubscription moved to ItemsSourceView.uno.cs; with I1 the finalizer is gone, so a comment in the MUX file points there instead of a ported UnListenToCollectionChanges. The repeated header bullet is gone (be52d10).
  8. 6ad6382 / 8b38597: LeakTestHelper.CollectWithoutDispatcher replaces the no-yield loop, Given_BindingMemoryLeak uses CollectAsync; 43444d0 folds my raise test into the reporter's (renamed ..._Is_Safe_And_Subscription_Removed).
  9. 31d2ca4: the finalizer queues the subscription itself with its source (no closure); Dispose uses a generic Run, no closure either.
  10. 96c1a0f / 80ed7b4: fixed here, TransitionManager subscribes weakly like the others.

@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 244235 found UI Test snapshots differences: skia-linux-screenshots: 2458, skia-windows-screenshots: 2458

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AppBarButtonTest.png
    • ApplicationViewMode.png-dark
    • ApplicationViewMode.png
    • Application_DispatcherShutdownMode.png
    • AppWindowClosing.png-dark
    • AppWindowTitleBar Properties.png
    • AppWindowPresenters.png
    • ArcSegment.png-dark
    • Attributed_text_FontSize_Changing.png
    • Attributed_text_Simple.png
    • AuthenticationBroker_Demo.png-dark
    • AutoBorderStretchwithbottommargin.png
    • AutoBorderStretchwithrightmargin.png
    • AutoBorderStretchwithtopmargin.png-dark
    • AutomationProperties_Relations.png
    • AutoBorderStretchwithtopmargin.png
    • AutomationProperties_StructureAndProps.png-dark
  • skia-windows-screenshots: 2458 changed over 2494

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AppBarButtonWithIconTest.png
    • ApplicationViewMode.png-dark
    • ApplicationViewSpanningRectsPage.png
    • AppWindowPositionAndSize.png-dark
    • AppWindowTitleBar Properties.png
    • ArcSegment.png
    • Arrange_Performance01.png-dark
    • AuthenticationBroker_Cancel.png
    • AuthenticationBroker_Demo.png-dark
    • AutomationProperties_Landmark.png-dark
    • AutomationProperties_Landmark.png
    • AutoSuggestBox_BitmapIcon.png-dark
    • AutoSuggestBox_BitmapIcon.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png

@Xiaoy312 Xiaoy312 added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/breaking-change Indicates that a PR should not merge because it contains breaking changes. labels Nov 6, 2026
The WASM interpreter's conservative stack scan keeps the elements alive
from stale slots, depending on frame layout: with the shared helper on
every run, with the inline loop only next to the other leak tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312 Xiaoy312 removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/breaking-change Indicates that a PR should not merge because it contains breaking changes. labels Nov 6, 2026
@nventive-devops

Copy link
Copy Markdown
Contributor

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

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

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AppBarToggleButtonTest.png-dark
    • ApplicationViewSizing.png
    • AppWindowPositionAndSize.png
    • Arrange_Performance01.png-dark
    • Attributed_text_Supserscript.png
    • AutoBorderStretchwithleftmargin.png
    • AutomationProperties_Landmark.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoSizedPathCentered.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • Basics Pivot Test.png-dark
    • Basics Pivot Test.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png
  • skia-windows-screenshots: 2458 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png
    • Accessibility_ScreenReader.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • ApplicationViewMode.png-dark
    • AppBarToggleButtonTest.png-dark
    • Application_DispatcherShutdownMode.png
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowTitleBar Properties.png
    • AppWindowFeatures.png
    • Attributed_text_Simple.png
    • AppXamlDefinedResources.png-dark
    • AuthenticationBroker_Demo.png
    • Attributed_text_FontSize_Changing.png
    • AutoBorderStretchwithtopmargin.png-dark
    • AuthenticationBroker_Demo.png-dark
    • AutomationProperties_Name.png-dark
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoSizedPathCentered.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutoSizedPathCentered.png

@mergify

mergify Bot commented Nov 6, 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.

@Xiaoy312
Xiaoy312 merged commit f81c672 into master Nov 6, 2026
52 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20261105/repeater-binding-leaks branch November 6, 2026 21:15
Xiaoy312 added a commit that referenced this pull request Nov 8, 2026
…r-26115

fix: Release subscriptions of never-loaded repeaters and collected bindings (backport #26115)
agneszitte added a commit that referenced this pull request Nov 9, 2026
…6.7/pr-26115

fix: Release subscriptions of never-loaded repeaters and collected bindings (backport #26115)
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.

6 participants