Repository navigation
Open
Labels
kind/enhancementNew feature or requesttriage/untriagedIndicates an issue requires triaging or verification
Description
What would you like to be added? 💡
One shared helper for "run this cleanup on the UI thread once this object is collected", used everywhere Uno does that today. There are currently several hand-rolled versions with different rules:
| Helper | Holds the source | Runs at | Used by |
|---|---|---|---|
WeakSourceSubscription<TSource, TState> + SubscriptionCleanup (src/Uno.UI/Helpers/, from #26115) |
raw weak GCHandle |
Low, batched (256 items or 3 ms) |
{Binding} INPC / indexer subscriptions, ItemsSourceView, ItemsRepeater, TransitionManager, ButtonBase / MenuFlyoutItem CanExecuteChanged |
DispatcherConditionalDisposable (src/Uno.UI/UI/Xaml/DispatcherConditionalDisposable.cs) |
ConditionalDisposable (WeakReference) |
inline on the UI thread, else Idle, one item each |
DependencyObject.Store property-changed callbacks, so also the DependencyObject-source branch of BindingItem |
ImageSource.SubscriptionLease (src/Uno.UI/UI/Xaml/Media/ImageSource.crossruntime.cs) |
raw weak GCHandle |
Low, one item each |
image data subscriptions |
BrowserHtmlElement.DomRemovalOnCollect (src/Uno.UI/NativeElementHosting/BrowserHtmlElement.cs) |
n/a (element id) | Idle, one item each |
DOM element removal on WASM |
The proposal: move the remaining three onto WeakSourceSubscription / SubscriptionCleanup (or a shared lower-level primitive under it), so they get the same guarantees:
- the source is held weakly, so a source collected together with its subscriber is not kept alive by the queued cleanup;
- removals are batched and time-bounded instead of one dispatcher item each;
- failures are logged with the source type, and a Debug line reports drained/pending counts.
Why is this needed? 🤔
- A single
{Binding}currently takes two cleanup paths with different priorities, depending on whether its source is anINotifyPropertyChangedor aDependencyObject. - Each copy re-solves the same finalizer pitfalls (finalizer ordering of
WeakReferencevsGCHandle, never throwing from a finalizer, thread affinity of the event source), and fixes made in one don't reach the others. - A page with thousands of bindings dropped at once currently queues thousands of
Idleitems throughDispatcherConditionalDisposable.
For which platforms 📱💻🖥️
All platforms 🌍
Anything else we need to know? 💬
Raised during the review of #26115, which introduced WeakSourceSubscription and kept the scope to the subscriptions involved in that fix. Things to check when migrating:
DispatcherConditionalDisposableruns the cleanup inline when already on the UI thread: decide whether batching may delay anything that relied on that.- Run the leak suites (
Given_BindingMemoryLeak,Given_BindingStaleHandlers,Given_ItemsRepeater_Leak,Given_CommandCanExecuteChanged) and the image source tests on every target.
Metadata
Metadata
Assignees
Labels
kind/enhancementNew feature or requesttriage/untriagedIndicates an issue requires triaging or verification
Activity