Skip to content

fix: Stop shared dependency objects retaining discarded elements and their DataContext (6.8 port of #25102) - #25839

Open
mikernet wants to merge 8 commits into
unoplatform:servicing/6.8from
mikernet:dev/mikernet/shared-dependency-objects-25099-6.8
Open

mikernet wants to merge 8 commits into
unoplatform:servicing/6.8from
mikernet:dev/mikernet/shared-dependency-objects-25099-6.8

Conversation

@mikernet

@mikernet mikernet commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: Related to #25099

6.8 port of #25102 to servicing/6.8, in sync with its current head (7650f1c, rebased on current master), which was reworked on top of #26123. That PR targets master and is approved; #25099 stays open until it merges.

PR Type:

🐞 Bugfix

What changed? 🚀

Dependency objects that are shared between elements (brushes, transforms, image sources, InputScopes, transitions, ...) kept the last element they were used by, or its DataContext, alive. Through that DataContext they could also keep the whole page alive after navigation. #25099 lists the reference chains.

servicing/6.8 already has two of the fixes: the weak single-parent association of a shareable value, with the guarded DataContext clear on release (#26142, the backport of #26123), and the ToolTip release (#26098, the backport of #25137 and #26096). This PR, rebased on current servicing/6.8, ports what #25102 still adds on top of them, plus a 6.x-only native fix with its tests. Eight commits:

  1. fix(transform): Stop shared transforms rooting discarded elements: fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102's ca59ff6, with its follow-up c2194bb (popup test portable to WinUI) folded in. Same code as fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102.
  2. fix(transform): Register brush, geometry and group handlers weakly: fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102's fb979a7, plus the two native partials that only 6.x has (Transform.Android.cs and Transform.Apple.cs), which now notify through the weak handlers instead of the removed Changed event. Same code as fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102 otherwise, apart from TransitionTarget, which 6.8 doesn't have.
  3. fix(dependencyobject): Hold a value's inherited DataContext weakly: the 6.x version of fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102's fde2c14, explained below. Unchanged from the previous version of this PR.
  4. fix(dependencyobject): Drop a collected parent's DataContext: fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102's 7650f1c, adapted to how 6.8 pushes a DataContext, explained below.
  5. fix(dependencyobject): Read an attached owner's DataContext (b4bacab): 6.8 only. It fixes a throw in commit 4's DataContext comparison, and the same throw in the guarded clear on release that servicing/6.8 already has from fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142, explained below.
  6. fix(transform): Hold a transform's native view weakly (5a60b04): 6.x only, for the native Android and iOS renderers, explained below.
  7. test(transform): Check a shared transform keeps its live view (a020124): its native-only test.
  8. test(transform): Skip the image checks on native Android (3724a5a): native Android's screenshots don't capture render transforms, so the transform tests' image checks run everywhere else; their collection checks still run there.

Dropped from the previous version of this PR, because servicing/6.8 has them now or because #25102 dropped them: the ToolTipService commit and its test, the weak _associatedParentRef and the ALC sweep and comment changes that went with it, the Given_CollectibleAlcAssociations rewrite, the rule that a collected parent counts as a second parent (and SingleParentNonFE_Parent_Collected_Then_Next_Parent_Counts_As_Second), and the unconditional DataContext clear in UnassociateParent (and SingleParentNonFE_Parent_Removes_Value_Then_Next_Parent_Starts_Clean). The guarded clear in UpdateChildBindable from #26142 is now the only clear on release.

Commit 3: why 6.8 needs a different DataContext half

On master, #23547 removed DataContext from every object that isn't a FrameworkElement. Such an object keeps the DataContext its element passes down in one plain field, and #25102 only had to make that field a weak reference.

6.8 doesn't have #23547, and can't take it, because it removes public API. On 6.8 every dependency object still has a DataContext property, and the value it inherits from its element is stored like any other property value, with a strong reference. So without commit 3, a shared value still keeps the view model of the last element that used it:

  • a shareable value (a brush, for instance) used by a single element that is then discarded: nothing tells the brush that the element is gone, and fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142's weak association doesn't release the DataContext;
  • any other value, such as a shared InputScope or the transitions in a shared TransitionCollection, which keeps the last view model pushed into it, however many elements use it.

It never grows (at most one view model per shared value), but the view model can reference its page.

Commit 3 makes only the inherited (Inheritance precedence) DataContext of objects that aren't UIElements non-owning:

  • DependencyObjectStore decides once per object (originalObject is not UIElement) and tells DependencyPropertyDetailsCollection, which applies it to the DataContext property only.
  • DependencyPropertyDetails keeps that value in one weak handle per object, of a private type so that no value set by user code can be taken for it. The handle is created with the first non-null value, and again after the value has been cleared; a change only retargets it, so it allocates nothing and takes no lock. Clearing the value frees the handle right away. GetEffectiveValue, GetBaseValue and GetInheritedValue unwrap it.
  • Once an object's DataContext has been animated, including by a VisualState setter that targets it, that object keeps its inherited DataContext strongly for the rest of its life, as all objects did before. DataContext is never coerced.

What stays the same:

  • UIElements keep their DataContext strongly. The element that passed a DataContext down keeps it alive for as long as it lives, so bindings on its brushes, row definitions, runs, triggers and so on keep working. Those bindings already held their source weakly.
  • A DataContext set on the object itself stays strong, for example flyout.DataContext = viewModel in code, or DataContext="{Binding Sub}" on a brush.
  • The single-parent rules of fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142 don't change.

Visible differences, all the same as on master (where these objects have no DataContext property) and in WinUI (which has no DataContext on them):

  • Reading DataContext on a brush, transform or other object that isn't a UIElement can return null after a garbage collection, once nothing else holds that view model (the element that provided it no longer has it), even if other elements still use the object. No DataContextChanged event is raised.
  • A binding added to such an object after that point resolves against null.

No public API change.

Commit 4: a collected parent's DataContext

Since #26142, a shareable value whose single parent was collected without unassociating counts that parent as no parent, and the next owner becomes its single parent, as in WinUI, where a destroyed parent removes itself from its values (CDependencyObject::ReleaseImpl -> ResetReferencesFromChildren -> RemoveParent). Two things were left behind:

  • The expired slot was reused with the DataContext the dead parent had pushed in. On 6.8, an owner pushes its DataContext into a new value only when the assignment changes the property's precedence, so after a same-precedence replacement (an element that already had a local Background, for instance) the value's bindings kept resolving against the old view model whenever it was still alive. The weak storage of commit 3 doesn't help then.
  • The dead parent never released its bindable slot, so _bindableHolderCount stayed one too high, and fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142's guarded clear on release (which waits for the last holder) never fired again for that value: the next owner's DataContext stayed behind once that owner let go.

When AssociateParent reuses an expired slot, it now clears the inherited DataContext unless it already is the new owner's, and leaves a value with its own parent other than the new owner alone (the same guard as the DataContext-change push, ApplyChildrenBindable). ReleaseCollectedParent frees the slot and gives back the dead parent's holder count, there and in the ALC sweep's collected-parent branch.

The difference from #25102: there the DataContext is cleared, and master's on-attach push in UpdateChildBindable then hands over the new owner's DataContext if it isn't null. 6.8 has no on-attach push. Its precedence-change push (TryApplyDataContextOnPrecedenceChange) runs before UpdateChildBindable, so a plain clear would drop the DataContext that push just gave the value; that is why the clear skips a DataContext that already is the new owner's. A reused value now ends where a value used for the first time ends in the same assignment: with the new owner's DataContext after a precedence change, and with none after a same-precedence replacement, where 6.8 pushes nothing into a new value either (unchanged) until the owner's DataContext changes.

Commit 5: an owner whose values live in an attached store

Commit 4's comparison and #26142's guarded clear on release in UpdateChildBindable both read the owner's DataContext with GetValue(DependencyProperty). That overload checks the property's owner when FeatureConfiguration.DependencyProperty.ValidatePropertyOwnerOnReadWrite is on, which is the default in Debug builds and in any build with a debugger attached. A plain object owner such as TextHighlighter, which isn't a dependency object on 6.8, keeps its values in an attached store. That store's DataContext property is owned by AttachedDependencyObject, while the store's type is TextHighlighter, so the check threw "The Dependency Property [DataContext] is owned by [AttachedDependencyObject] and cannot be used on [TextHighlighter]".

TextBlock hits commit 4's read on every draw with a selection: it creates a TextHighlighter for its selection brush, and the previous highlighter has been collected by then. #26142's read throws when a highlighter's brush is replaced. These reads now go through the stores' DataContext details, as SetMentoredChild and RepropagateMentoredChildrenDataContext already do. The values read don't change; only the owner check is skipped.

#25102 and master's #26123 don't need this: on master only a FrameworkElement has a DataContext property, and these reads go through GetInheritedDataContextValue().

Commit 6: a transform's native view on Android and iOS

The native renderers, which only 6.x has, give a transform the view it is applied to (Transform.View), for their GPU animations. NativeRenderTransformAdapter set it and nothing cleared it, so on Android and iOS a transform shared through a Style setter still kept the last element styled with it alive, with its DataContext, after commit 1's weak change registration.

  • Transform.View is now held weakly, in a new WeakReference each time it is set.
  • TransformGroup's Reset branch clears it on the children it drops, as OnChildRemoved already does.

Which element View points to doesn't change: it is still the last element the transform was applied to, so, as before, a native animation of a shared transform only moves that element.

View can now be gone while a storyboard still targets the transform. That was already possible for a transform that was never applied, and on Android it threw in the animator's prepare step. So the Android animator reads View once. Without a view it uses a plain value animator, which doesn't animate anything on screen: the transform gets the final value when the animation ends. Its prepare, complete and pivot steps and TryGetNativeAnimatedValue skip the native view. The iOS animator already handled a null view; it now reads View once. Skia and WebAssembly don't have Transform.View.

Known remaining gap: shared flyouts

A flyout that is shared (app-level or static) and attached through Button.Flyout, FlyoutBase.AttachedFlyout, or the flyout of a SplitButton or DropDownButton, still keeps the view model of the last element it was attached to. With commit 3 the flyout's own DataContext is weak, but 6.8 copies it into UIElements the flyout owns, and those hold it strongly:

  • Flyout sets it on its Content as a local value, whenever its DataContext changes, even if the flyout never opens;
  • MenuFlyout passes it to its items, which are UIElements;
  • FlyoutBase copies it onto its popup as a local value.

ContextFlyout is less exposed: its DataContext is cleared when its element unloads.

Master doesn't have this problem: it removed the popup copy, and #23547 changed how flyouts get their DataContext. Doing the same here would change 6.8's flyout DataContext behavior (content and items would no longer see the owner's DataContext while closed), which is out of scope for a servicing fix. This PR doesn't change it either way.

Performance

Commit 3 keeps one small object (32 bytes on 64-bit, holding a weak GC handle, with a finalizer) per object that receives a DataContext from its element. In a template that means one per VisualStateGroup, groups collection, VisualStateManager and content Run: 4 per Button, about 28 per realized ListView item in the benchmark below. It is created with the first non-null value, and again after the value has been cleared (for example when the element of a ContextFlyout unloads, or when a shared value loses its only parent). Clearing frees it right away; otherwise its finalizer frees it when the object is collected. A DataContext change only retargets the handle: no allocation and no lock. Commit 4 only adds work when a value whose parent was collected is reused, and commit 5 makes the reads it touches skip the owner check; commits 1 and 2 don't touch the DataContext path.

Measured on a quiet machine, on Skia desktop and WebAssembly: single runs per platform, with a temporary local switch (not committed) that brings back the strong storage from before commit 3. Both modes run in the same build and process, alternating every round (ABBA); medians of 16 timed rounds after 3 warm-up rounds. "Create" includes adding to the tree and layout, and every phase runs under a non-null DataContext. Weak (commit 3) vs strong storage:

Skia desktop WebAssembly (Chrome, interpreter)
300 Buttons: create / detach / full GC +3% / 0% / +1% 0% / +1% / −1%
ListView, 200 items (45 realized): create / detach / full GC +1% / 0% / +3% +1% / +1% / +1%
500 DataContext changes on 20 Buttons, a new view model each time +1% +2%
500 DataContext changes on 20 Buttons, two alternating view models +2% +2%
new Content string on 20 Buttons, 100 times 0% +2%

For scale, with strong storage:

  • 300 Buttons take about 90 ms to create on desktop and 920 ms on WebAssembly.
  • The 500 DataContext changes take about 14 ms on desktop and 310 ms on WebAssembly.

Handles and bytes:

  • Count: a round of 300 Buttons allocates 1200 handles, 4 per Button. The states and storyboards don't receive the DataContext: VisualStateGroup.States is created with isAutoPropertyInheritanceEnabled: false, and a VisualState disables inheritance and materializes its content only when used.
  • Bytes: about 37 KB per round on desktop and 19 KB on WebAssembly, on top of about 44 MB and 29 MB for the round.
  • Earlier busy runs: an earlier run on a busy machine showed detach up to 60% slower; on the quiet machine it is 0%.

Sharing one weak handle per inherited value (a ConditionalWeakTable keyed on the value) cut the handles allocated by 75% to 93% in the same benchmark, but cost +5% to +10% on DataContext changes. It isn't part of this PR. Pooling the per-object handles through WeakReferencePool was dropped too: only returned handles are reused, so it still allocates per object.

Tests

From #25102:

  • Given_Transform: When_RenderTransform_Shared_By_Style_Then_Discarded_Elements_Collected, When_RenderTransform_Shared_By_Popup_Style_Then_Discarded_Popups_Collected, When_Projection_Shared_By_Style_Then_Discarded_Elements_Collected, When_Transform_Shared_By_Brushes_Then_Discarded_Brushes_Collected, When_Transform_Shared_By_Geometries_Then_Discarded_Elements_Collected, When_Transform_Shared_By_TransformGroups_Then_Discarded_Groups_Collected and the guard When_TransformGroup_Children_Cleared_Then_Removed_Child_Collected. Same file as in fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102.
  • Given_BindingMemoryLeak: When_BrushShared_SingleOwner_Removed_Then_Owner_And_ViewModel_Collected, When_TransitionsShared_Removed_Then_ViewModel_Collected and When_InputScopeShared_Removed_Then_ViewModel_Collected. 6.x declares Transitions on FrameworkElement, and not at all on the native mobile targets, so the transitions test uses FrameworkElement.TransitionsProperty and is compiled out there.
  • Given_UIElement.DataContext: SingleParentNonFE_Parent_Collected_Then_Next_Parent_Starts_Clean (commit 4) and the guard SharedNonFE_ObjectBinding_Subtree_Severed_Then_Bound_Value_Released (commit 3).

New for 6.x, in Given_Transform (commit 7, Android and iOS only): When_RenderTransform_Shared_By_Style_Then_View_Is_Last_Live_Element. A transform shared through a Style by two live Borders still has the second one as its View after a full collection, so the native animators keep finding the view to animate. It's a guard: it passes with and without commit 6.

New for 6.x, in Given_UIElement.DataContext:

  • SingleParentNonFE_Parent_Collected_Then_Next_Parent_Gets_What_A_New_Value_Gets (commit 4), with a same-precedence replacement and with a precedence change: a bound brush whose first owner was collected while that owner's view model stays alive, assigned to a new owner that has a DataContext, never shows the dead owner's view model and ends with what a brush used for the first time gets in the same assignment (the new owner's DataContext after a precedence change, none after a same-precedence replacement).
  • SingleParentNonFE_Parent_Collected_Then_Next_Parent_Has_Attached_Store and SingleParentNonFE_Released_By_Owner_With_Attached_Store (commit 5): with the owner validation on, a TextHighlighter takes a brush whose first owner was collected (the brush must also drop the dead owner's DataContext), and replaces its brush, without throwing.
  • NonFE_Inherited_DataContext_Survives_GC_While_Owner_Alive, NonFE_Binding_Added_After_DataContext_Pushed_Then_Resolves, NonFE_DataContext_Bound_To_Sub_Then_Resolves_And_Updates and NonFE_Local_DataContext_Stays_Owned (commit 3, unchanged): they force garbage collections and check that objects that aren't UIElements, and their bindings, still resolve to the right view model, never to the weak handle or to nothing, and that a DataContext set on the object itself stays owned.

Validation

On Skia desktop (Release), at 97a2f17 (commit 4): Given_Transform, Given_BindingMemoryLeak, Given_UIElement (including the DataContext tests), Given_CollectibleAlcAssociations, Given_ResourceDictionary_DataContext, Given_ToolTip, Given_FrameworkElement_And_Leak, Given_SharedTemplate_DataContext, Given_PlainDP_SharedValue and Given_Flyout_PropertyPropagation: 700 test cases, 688 passed, 11 failed, 1 skipped. The 11 failures fail the same way on an untouched servicing/6.8 build on the same machine: 10 Given_UIElement layout-rounding tests at 125% scaling (ActualOffset, TransformToVisual, clip and nesting cases) and Given_FrameworkElement_And_Leak.When_Add_Remove(CommandBarFlyout_Leak).

At b4bacab (commit 5), on Skia desktop (Release), the same classes plus Given_TextBlock: 851 test cases, 838 passed, 13 failed, 4 skipped. 11 failures are the ones above. The other two are Given_TextBlock.When_Inlines_Transitively_Change (a pixel check) and When_IsTextSelectionEnabled_CRLF (a clipboard check, and other processes on the machine share the clipboard). They failed the same way on a 6.8 build without commits 4 and 5 on the same machine.

At 3724a5a (the head), on Skia desktop (Release), the same classes: 848 test cases, 831 passed, 13 failed, 4 skipped, with the same 13 failures as at b4bacab.

Red and green, on Skia desktop, with a temporary local switch (not committed) that turns off parts of the product change:

  • commit 4 off: SingleParentNonFE_Parent_Collected_Then_Next_Parent_Starts_Clean and the same-precedence row of SingleParentNonFE_Parent_Collected_Then_Next_Parent_Gets_What_A_New_Value_Gets fail: the brush keeps the dead owner's view model;
  • commit 4 with a plain clear, as on master: the precedence-change row fails: the brush loses the new owner's DataContext and falls back to its default color;
  • commit 3's weak storage off, commit 4 on: the three Given_BindingMemoryLeak DataContext tests fail, the commit 4 tests pass.

These two ran with an earlier form of commit 4 that set the new owner's DataContext instead of keeping it; its holder-count part and commit 3 are unchanged:

  • commit 3's weak storage and commit 4 off (the servicing/6.8 DataContext code): the three Given_BindingMemoryLeak DataContext tests and Starts_Clean fail; the other Given_BindingMemoryLeak and Given_UIElement DataContext tests pass;
  • commit 4 without the holder-count give-back: Starts_Clean fails at its last step.

Commit 5 off: both of its tests fail with the owner validation exception, the first in AssociateParent and the second in UpdateChildBindable's clear on release.

With the full change, all of them pass. The transform tests are unchanged from the previous round, where they failed without their commits. Commit 3's NonFE_* tests and SharedNonFE_ObjectBinding_Subtree_Severed_Then_Bound_Value_Released are guards: they pass with and without the change.

In Uno.UI.UnitTests (Release, net10.0), the only failures are 13 calendar tests (When_Gregorian_FixedDate* and When_DateTimeOffset_Is_Next_Day_If_Converted_To_Utc) that depend on the machine's time zone, as in the previous round.

Commits 6 to 8 (native only): Uno.UI builds for net10.0-android and net10.0-ios26.0, and Uno.UI.RuntimeTests.netcoremobile, including commit 7's test, builds for net10.0-android. Native runtime tests, Android, on a local API 28 emulator. 6.8's native runtime-test project needs a few unrelated test files left out to compile there. The mutant is the head with commit 6's product change reverted:

Test head mutant
When_RenderTransform_Shared_By_Style_Then_Discarded_Elements_Collected collected not collected
When_RenderTransform_Shared_By_Popup_Style_Then_Discarded_Popups_Collected passes not collected
When_Transform_Shared_By_TransformGroups_Then_Discarded_Groups_Collected collected not collected
When_RenderTransform_Shared_By_Style_Then_View_Is_Last_Live_Element (guard) passes passes
When_TransformGroup_Children_Cleared_Then_Removed_Child_Collected (guard) passes passes

The screenshot checks of the transform tests failed on native Android with and without commit 6. A native-Android screenshot doesn't capture render transforms at all, not even an unshared ScaleTransform (checked with a local probe test), so commit 8 skips only those image checks there. With commit 8, every Given_Transform test passes on the emulator (the projection one is Skia-only). Given_Storyboard.When_Begin_Stop_Begin times out on the emulator with and without commit 6.

Native iOS tests: not run. servicing/6.8 lacks the scene life-cycle fixes that the iOS 27 SDK needs: the SamplesApp, built with the current iOS 27 SDK, launches to a black window on the simulator.

Not run this round: Skia WebAssembly runtime tests. Commits 1 to 3 are unchanged since the previous round, where they passed on WebAssembly and the native builds succeeded for net10.0-android, net10.0-ios26.0, net10.0-maccatalyst26.0, net10.0-tvos26.0, net9.0-android and net9.0-ios18.0. Commits 4 and 5 only change shared C# in DependencyObjectStore.

PR Checklist ✅

@mikernet
mikernet force-pushed the dev/mikernet/shared-dependency-objects-25099-6.8 branch from f9e8686 to 2d8b6f9 Compare October 29, 2026 22:43
@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform labels Oct 29, 2026
@mikernet

Copy link
Copy Markdown
Contributor Author

Force-pushed a fix to commit 4: it removed Transform.Changed, but the 6.x-only Transform.Android.cs and Transform.Apple.cs still raised it, so native Uno.UI didn't compile. They now notify through the weak handlers, as NotifyChanged does. The native Uno.UI builds succeed for net10.0-android, net10.0-ios26.0, net10.0-maccatalyst26.0, net10.0-tvos26.0, net9.0-android and net9.0-ios18.0. Commit 5 is unchanged; the description is updated.

@agneszitte

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@agneszitte

Copy link
Copy Markdown
Member

@MartinZikmund can you help follow up on this PR please

@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 242669 did not find any UI Test snapshots differences.

@MartinZikmund MartinZikmund left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by reading the code against this PR's head, servicing/6.8 and the WinUI C++ sources. I haven't built or run it.

I'd hold this until #25102 settles, since the port should follow whatever it ends up doing:

  1. The base has moved. servicing/6.8 already has the #26123 backport (5a5cce0 and follow-ups), and six files now conflict, including DependencyObjectStore.Binder.cs and ToolTipService.cs. "Same code as master" in the description is no longer accurate.
  2. Dead-parent rule. This port carries the same "a collected parent counts as a second parent" rule that conflicts with #26123. See my review on #25102, including the stale DataContext to handle when a collected parent's slot is reused.

The weak inherited storage in commit 5 looks right. The readers I traced in DependencyPropertyDetails unwrap the value, ModifiedValue stays strong, and the wrapper's handle is disposed when the value is unset.

An open question for servicing, rather than a defect: is this acceptable risk for a 6.8 fix? By the PR's own numbers, WebAssembly DataContext changes cost +2% to +8%. Each affected object gets a finalizable handle, public DataContext on non-UIElements can read null after a GC, and the shared-flyout leak remains.

NativeRenderTransformAdapter subscribed strongly to Transform.Changed and
only unsubscribed when the element's RenderTransform was replaced, so a
transform shared through a Style setter accumulated one handler per element
ever styled with it, keeping every discarded element (and its inherited
DataContext) alive. The adapter now registers through a weak registration
on the transform, so the transform never roots its subscribers.

unoplatform#25099
Transforms are multi-parent shareable, as in WinUI, so one transform can
outlive the brushes, geometries and TransformGroups that use it (a
resource referenced from a template, for instance). Each of them still
subscribed to the strong Transform.Changed event, so the shared
transform kept every discarded one alive, and through a geometry's
GeometryChanged handler also the Path it draws or the element it clips.
WinUI tracks those parents with non-owning pointers.

They now go through RegisterChanged and hold the registration, like the
render transform adapter, Popup and the projection owner. With no
strong subscriber left, the strong Changed events of Transform and
Projection are removed so the leak cannot come back through them.
TransformGroup now also handles the Reset that Children.Clear() raises
without the removed items, so it lets go of the cleared children.

The 6.x-only native partials (Transform.Android.cs, Transform.Apple.cs)
raised the removed Changed event too; they now notify through the weak
handlers, as NotifyChanged does.
A DependencyObject that isn't a UIElement, used as a property value,
keeps the DataContext its element pushes into it, so bindings added or
resumed on it later resolve against it. That value was held strongly,
so a long-lived shared value (a style setter value, a static brush, a
TransitionCollection or an InputScope) kept the DataContext of the last
element it was applied to, and with it that element's page, alive
after navigation.

Hold it weakly, as WinUI does: these objects have no DataContext there,
their bindings resolve through a non-owning inheritance-context mentor,
and the DataContext belongs to the mentor. Master holds its equivalent
cache weakly. 6.x stores that DataContext as a property value at
Inheritance precedence, so its DependencyPropertyDetails now keeps that
value in one weak handle per object, retargeted in place, and every
reader unwraps it. A DataContext set on the object itself, and one that
has been animated, stay strong.

unoplatform#25099
A shareable value whose single parent was collected without
unassociating takes the next owner as its single parent again, but kept
the DataContext the dead parent had pushed into it. On 6.x an owner
pushes its DataContext into a new value only when the assignment
changes the property's precedence, so after a same-precedence
replacement the value's bindings kept resolving against the old view
model whenever that view model was still alive, and the weak inherited
DataContext does not help then.

WinUI has no such state: a destroyed parent removes itself from its
values (CDependencyObject::ReleaseImpl -> ResetReferencesFromChildren),
which takes the inheritance context with it. When the expired slot is
reused, clear the inherited DataContext unless it already is the new
owner's (a precedence-changing assignment has pushed it by then), and
leave a value with its own parent alone, like ApplyChildrenBindable.
The reused value then ends where a value used for the first time would.

The dead parent never released its bindable slot either, so it kept
counting as a holder and the guarded clear on release, which waits for
the last holder, never fired again for that value: the next owner's
DataContext stayed behind once it let go. Give that slot back when the
expired association is freed, here and in the ALC sweep.

unoplatform#25099
@mikernet
mikernet force-pushed the dev/mikernet/shared-dependency-objects-25099-6.8 branch from 2d8b6f9 to 97a2f17 Compare November 13, 2026 04:24
@mikernet

Copy link
Copy Markdown
Contributor Author

I rebased onto current servicing/6.8 and brought the port in line with #25102's current head (0efaf28), so it no longer carries what #26142 and #26098 already backported. The PR is now four commits: the transform/projection registrations (da95ebd, ed4e5d5), the weak inherited DataContext (eea6fb2, unchanged) and the expired-slot handling (97a2f17).

  1. The base has moved. Dropped, since servicing/6.8 has them now: the ToolTipService commit and its test (fix: Release the current ToolTip when it closes (backport #25137, #26096) #26098), the weak _associatedParentRef, my ALC sweep and comment changes in DependencyObjectStore.alc.cs, Application.Alc.cs and ResourceDictionary.alc.cs, and the Given_CollectibleAlcAssociations rewrite (fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142). The description no longer says "same code as master". It says which commits match fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102 and where 6.8 differs: the two 6.x-only native Transform partials in commit 2, the DataContext storage in commit 3, and one step in commit 4 (below).

  2. Dead-parent rule. The port now keeps fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142's rule as is: a collected parent counts as no parent. SingleParentNonFE_Parent_Collected_Then_Next_Parent_Counts_As_Second is gone. I also dropped the unconditional clear in UnassociateParent (and its test, ..._Removes_Value_Then_Next_Parent_Starts_Clean), so fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142's guarded clear in UpdateChildBindable is the only clear on release. For the stale DataContext on a reused slot, 97a2f17 ports 0efaf28: when AssociateParent reuses an expired slot, it drops the DataContext the dead parent left, and ReleaseCollectedParent gives back the dead parent's _bindableHolderCount, also in the ALC sweep's collected-parent branch. Without that give-back, fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142's guarded clear never fired again for that value.

    One step differs from master. Master clears there, then its on-attach push in UpdateChildBindable hands over the new owner's DataContext if it isn't null. 6.8 has no on-attach push. Its precedence-change push (TryApplyDataContextOnPrecedenceChange) runs in InnerSetValue before the callbacks reach UpdateChildBindable, so a plain clear would drop the DataContext that push just gave the value. The port therefore clears only when the value's DataContext isn't already the new owner's, and leaves a value with its own parent other than the new owner alone (the same guard as the DataContext-change push, ApplyChildrenBindable). A reused value now ends like a value used for the first time in the same assignment: with the owner's DataContext after a precedence change, and with none after a same-precedence replacement, where 6.8 pushes nothing into a new value either (unchanged).

    Tests, on Skia desktop: SingleParentNonFE_Parent_Collected_Then_Next_Parent_Starts_Clean (from fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102) and the new SingleParentNonFE_Parent_Collected_Then_Next_Parent_Gets_What_A_New_Value_Gets (same-precedence and precedence-change rows, each compared with a brush used for the first time). With commit 4 switched off in a local build, Starts_Clean and the same-precedence row fail: the brush keeps the dead owner's red. With a plain clear, the precedence-change row fails: the brush loses the new owner's DataContext. Without the holder-count give-back, Starts_Clean fails at its last step.

    The weak inherited storage is unchanged from the version you reviewed.

  3. Servicing risk. The facts, for whoever decides:

    • Commits 1 and 2 are the same code as fix: Stop shared dependency objects retaining discarded elements and their DataContext #25102 (plus the two native partials), and only change how transforms, projections, brushes, geometries and groups subscribe to each other.
    • Commit 3 is where the cost is. I measured 1000 DataContext changes on 20 controls again on Skia desktop at this head, in one build with a local switch for commit 3's weak storage. The machine was loaded and run medians swung by up to 2x, so the medians don't separate. The lowest timed rounds give +5% (Button) to +8% (Border, TextBox), in line with the previous round's medians (+4% to +8%). I didn't measure WebAssembly again. Commit 3 hasn't changed since the +4% to +8% measured there (medians; +2% to +8% across runs), and the base changes since then (fix: Stop shared values on plain DPs retaining their owners (backport #26123) #26142 among them) are on code both builds share.
    • Each object that isn't a UIElement and receives a non-null DataContext from its element gets one 32-byte object holding a weak GC handle, with a finalizer. It is freed when that DataContext is cleared, otherwise by the finalizer when the object is collected.
    • DataContext on such an object (a public property on 6.8) can read null after a GC once nothing else holds that view model, even while other elements use the object. No DataContextChanged is raised. Master and WinUI have no such property.
    • The shared-flyout retention stays as it is: this PR doesn't change it.
    • Commit 4 doesn't depend on commit 3: with commit 3's weak storage switched off in a local build, the commit 4 tests pass. Commits 1, 2 and 4 could go in without commit 3. The leaks commit 3's three Given_BindingMemoryLeak tests cover (a shared brush, TransitionCollection or InputScope keeping the last owner's view model) would then remain on 6.8.

@mergify

mergify Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

mikernet added a commit to Singulink/uno that referenced this pull request Nov 13, 2026
…alue (port)

Port of the review fix in unoplatform#25839 (commit 97a2f17), on
top of this build's port fd40bf9.

On 6.x an owner pushes its DataContext into a new value
(TryApplyDataContextOnPrecedenceChange) before the value is associated
with it, and only when the assignment changes the property's
precedence. The plain clear fd40bf9 added where a collected parent's
slot is reused therefore wiped the DataContext a precedence-changing
assignment had just pushed. The clear now keeps the inherited
DataContext when it already is the new owner's, so a reused value ends
where a value used for the first time would: the owner's DataContext
after a precedence change, none after a same-precedence replacement.
mikernet added a commit to Singulink/uno that referenced this pull request Nov 13, 2026
Fix for 7546379, the port of unoplatform#25839's review fix
(97a2f17), which upstream gets in the same form.

Where a collected parent's slot is reused, the value now compares its
DataContext with the new owner's, read with GetValue(DependencyProperty).
That overload checks the property's owner when
ValidatePropertyOwnerOnReadWrite is on (Debug builds, or any build with a
debugger attached). A POCO owner such as TextHighlighter keeps its values
in an attached store, whose DataContext property is owned by
AttachedDependencyObject while the store's type is the POCO's, so the
check threw "The Dependency Property [DataContext] is owned by
[AttachedDependencyObject] and cannot be used on [TextHighlighter]".
TextBlock hits it on every draw with a selection: it creates a
TextHighlighter for the selection brush, whose previous highlighter has
been collected. Both reads now go through the stores' DataContext
details, as SetMentoredChild and RepropagateMentoredChildrenDataContext
already do.
The expired-slot step in AssociateParent (previous commit) and the
guarded release clear in UpdateChildBindable (unoplatform#26142) compare a value's
DataContext with its owner's, read with GetValue(DependencyProperty).
That overload checks the property's owner when
ValidatePropertyOwnerOnReadWrite is on (Debug builds, or any build with a
debugger attached). A POCO owner such as TextHighlighter keeps its values
in an attached store, whose DataContext property is owned by
AttachedDependencyObject while the store's type is the POCO's, so the
check threw "The Dependency Property [DataContext] is owned by
[AttachedDependencyObject] and cannot be used on [TextHighlighter]".
TextBlock hits the first one on every draw with a selection: it creates
a TextHighlighter for its selection brush, whose previous highlighter
has been collected. The second one fires when a highlighter's brush is
replaced. All these reads now go through the stores' DataContext
details, as SetMentoredChild and RepropagateMentoredChildrenDataContext
already do.
@mikernet

Copy link
Copy Markdown
Contributor Author

servicing/6.8's #26142 backport reads the owner's DataContext with GetValue(DependencyProperty) in its guarded clear on release. That throws under ValidatePropertyOwnerOnReadWrite (Debug builds, or a debugger attached) when the owner is an attached store, such as TextHighlighter's; TextBlock hits the same throw through this PR's own read on every draw with a selection.
b4bacab fixes both reads (they now go through the stores' DataContext details) and adds a test for each that fails without it.
Master's #26123 isn't affected: it reads through GetInheritedDataContextValue().

mikernet added a commit to Singulink/uno that referenced this pull request Nov 14, 2026
Takes Uno's servicing/6.8 from 6951c2c up to 5254ace (42 pull
requests). Conflicts, by area:

IME and TextBox (unoplatform#25984, backport of unoplatform#25804; unoplatform#25952, backport of unoplatform#25619;
unoplatform#25976, backport of unoplatform#25818)
- Takes upstream's composition design (unoplatform#25804): the browser's input is
  the source of truth for the text, compositions included. This drops
  the composition parts of the unoplatform#24502 port (90746b8): its
  TypeScript composition handling, the StartIndex/TextChangePending
  event arguments, the IsReadOnly forwarding to the hidden input, and
  its Given_TextBox.BrowserSoftKeyboard tests.
- Keeps the non-IME browser fixes on top of it, in the form their
  master pull requests have on unoplatform#25804: Enter raised once per press and
  tracked by key code (unoplatform#25174, with Given_TextBox.BrowserEnterKey from
  master in place of the Enter tests that lived in the dropped file),
  the iOS refocus on tap (unoplatform#25185), pastes without text and isIOS from
  BrowserInputHelper.
- Moves the unoplatform#26005 MaxLength fixes onto unoplatform#25804's native input path, as
  master has them: a refused browser edit keeps the TextBox's selection,
  TextBoxView.UpdateTextFromNative reports whether the edit went in, and
  the IME keeps its range on the applied text (master be85699, which
  d226897 had ported onto the unoplatform#24502 IME). Adds that commit's browser
  and platform-applied IME tests.
- TextBox.pointers.skia.cs: upstream's file (unoplatform#25619 iOS touch editing,
  unoplatform#25818, unoplatform#25804), with the unoplatform#25126 port (the hold acts when it starts,
  a touch right-tap keeps the caret) in the form master's unoplatform#25126 branch
  has it on unoplatform#25619, including focusing before the iOS hold timer acts
  and its iOS not-focusable test.

Pointers (unoplatform#25976, backport of unoplatform#25818)
- Tapped and RightTapped are raised once the PointerReleased bubbled
  (unoplatform#25818), with the unoplatform#25732 port's window coordinates (2-argument
  routed event args, RawPosition for ContextRequested), as master's
  unoplatform#25732 branch has them.
- The release wrapper of unoplatform#25818 keeps the unoplatform#25126 port's
  StopContextMenuTimer at the start of the release.

DependencyObject (unoplatform#26142, backport of unoplatform#26123)
- Takes upstream, then the code of unoplatform#25839 (97a2f17), which replaces
  this branch's unoplatform#25102 ports (800247f, be41da6, fd40bf9,
  7546379). DependencyObjectStore.Binder.cs, .alc.cs,
  Application.Alc.cs, ResourceDictionary.alc.cs and their tests now
  match unoplatform#25839; this drops 800247f's own
  SingleParentNonFE_Parent_Removes_Value_Then_Next_Parent_Starts_Clean
  test, which unoplatform#25839 doesn't have.

Imaging (unoplatform#25597, unoplatform#25915, unoplatform#25911, unoplatform#25897)
- Keeps this branch's side: it has the later forms of these fixes
  (unoplatform#25124, unoplatform#25559, unoplatform#25633 and unoplatform#26370 ports), where upstream has the
  6.8-only unoplatform#25597 design and earlier snapshots. Upstream's shared
  download, IgnoreImageCache and failed-load fixes are covered by
  SharedImageDecode. Adds upstream's When_Source_Outlives_Brushes test.

ToolTip (unoplatform#26098, backport of unoplatform#25137 and unoplatform#26096)
- Keeps this branch's unoplatform#25137 port and adds unoplatform#26096 in master's form: the
  service releases only a ToolTip it opened, and leaves one the app
  opened during the show delay to the app. Keeps both sides' tests.

Flyout (unoplatform#26062, backport of unoplatform#26060)
- This branch had the same commits already; keeps the "Keep
  non-resizable flyouts in window" port and its tests.

Also removes a helper pair in Given_AccessibleTextBox that both sides
added.
mikernet added a commit to Singulink/uno that referenced this pull request Nov 14, 2026
Brings in the hotfix for the DataContext reads of an attached owner.
DependencyObjectStore.Binder.cs and Given_UIElement.DataContext.cs take
the form of unoplatform#25839 at b4bacab, which also covers the
release clear that servicing/6.8 added in UpdateChildBindable and adds
SingleParentNonFE_Released_By_Owner_With_Attached_Store.

@MartinZikmund MartinZikmund left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikernet thanks for keeping this port in lockstep with #25102, and for the very thorough write-up. The rebase on current servicing/6.8 addresses both points from my last review: the parts that are already backported are gone, and the collected-parent handling now follows master. I compared each commit against #25102's head 0efaf28. The transform/projection registrations are identical to master, commit 4 is adapted correctly to 6.8's precedence-change push (TryApplyDataContextOnPrecedenceChange runs before RaiseCallbacks -> UpdateChildBindable -> AssociateParent, so keeping a DataContext that already matches the new owner's is right), and commit 5 reads the same values as before, just without tripping the owner check. The weak inherited storage in DependencyPropertyDetails also holds up: every reader unwraps, ModifiedValue only ever gets the strong value, and the in-place retarget is only reachable through _inheritedValue/_value.

Two things before this can go into a servicing branch:

  1. Native Android/iOS still root the last element through Transform.View. This is 6.x-only, so master doesn't need it. NativeRenderTransformAdapter's constructor does transform.View = owner under __ANDROID__ || __APPLE_UIKIT__ (and TransformGroup.View pushes it into every child). That is a strong reference from the shared transform to the last element it was applied to, and nothing clears it: the adapter is only disposed when RenderTransform changes, and Dispose/Cleanup never reset View. So on native mobile, a Style-shared transform still keeps the last discarded element alive, together with its DataContext and page. When_RenderTransform_Shared_By_Style_Then_Discarded_Elements_Collected and the Popup variant have no platform condition, so they should fail on the 5th element on native. PR CI won't show this because the "Tests - Android Native" and "Tests - iOS Native" stages are skipped on PR builds (they were skipped in 242669 too). Could you either hold View weakly (it's only used to find the view to animate), or at least clear it when the adapter's owner goes away? The TransformGroup Reset branch should also clear View on the removed children, since _childRegistrations already knows which ones they are. If you'd rather keep native out of scope, exclude those tests on native and say so in the description, but I'd prefer the fix.

  2. Creation-time cost of commit 3 hasn't been measured. The numbers cover DataContext changes. What I'm more worried about on 6.8 is load: every non-UIElement that receives a non-null inherited DataContext now allocates a finalizable ManagedGCHandle plus a GCHandle.Alloc. On 6.8 that's not only brushes and runs. VisualStateManager.VisualStateGroups, VisualStateGroup.States and VisualState.Storyboard/Setters are all ValueInheritsDataContext, so each templated control instance gets one handle per group, state and storyboard (roughly ten for a plain Button). Master rents these from WeakReferencePool, so it doesn't pay this per object. Could you measure realizing something template-heavy (for example a few hundred Buttons, or a ListView page navigated to and from), with and without commit 3, on WASM in particular? If it shows up, pooling the handle (or keeping it in a side field rented from WeakReferencePool) would remove the finalizer cost. That's the main risk call for taking this into a servicing release, so I'd like numbers before approving.

Everything else looks good to me. I read the code against the PR head, servicing/6.8 and #25102. I haven't built it or run the tests.

On Android and iOS a transform keeps the view it is applied to in View,
for its GPU animations. NativeRenderTransformAdapter set it and nothing
cleared it, so a transform shared through a Style setter still kept the
last element styled with it alive, with its DataContext, after the weak
change registration. View is now held weakly, and the TransformGroup
Reset branch clears it on the children it drops, as OnChildRemoved
already does.

View can now be gone while a storyboard still targets the transform, as
it already could for a transform that was never applied, which threw in
the Android animator's prepare step. The Android animator now reads View
once; without a view it uses a plain value animator, whose value is
applied when it ends, and its prepare, complete and pivot steps skip the
native view. The iOS animator, which already checked for a null view,
reads it once as well.
Transform.View is now held weakly. On Android and iOS, check that a
transform shared through a Style still points at the last element it
was applied to while that element is alive, after a full collection,
so the native animators keep finding the view to animate.
The shared-transform tests check twice: that discarded elements, brushes,
geometries and groups are collected, and with a screenshot that the
survivor still follows the transform. On native Android the screenshot
doesn't capture render transforms at all, not even an unshared one, so
the image checks failed there whatever the transform code did. They now
run everywhere else, and the collection checks still run on native
Android, where they fail without the native fix.
@mikernet

Copy link
Copy Markdown
Contributor Author
  1. Native Transform.View: fixed in 5a60b04 (fix(transform): Hold a transform's native view weakly). The tests keep no platform condition; only their screenshot checks are skipped on native Android (see below).

    • Transform.View is now held weakly, in a new WeakReference each time it's set. It's only used to find the view to animate.
    • The TransformGroup Reset branch clears View on the children it drops, as OnChildRemoved already does.
    • Which element View points to is unchanged: still the last one the transform was applied to. As before, a native animation of a shared transform only moves that element.
    • View can now go null while a storyboard still targets the transform. That was already possible for a transform that was never applied, and on Android it threw in the animator's prepare step. So the Android animator now reads View once. Without a view it uses a plain value animator, which moves nothing on screen: the transform gets the final value when the animation ends. Its prepare, complete and pivot steps and TryGetNativeAnimatedValue skip the native view. The iOS animator already handled null; it now reads View once.
    • a020124 adds an Android/iOS guard test: a transform shared through a Style by two live Borders still has the second one as its View after a full collection.

    Validation: Uno.UI builds for net10.0-android and net10.0-ios26.0.

    Android: native runtime tests, run locally on an API 28 emulator. 6.8's native test project needs a few unrelated test files left out to compile there. I ran head vs mutant, where the mutant is the head with 5a60b04's product change reverted:

    Test head mutant
    When_RenderTransform_Shared_By_Style_Then_Discarded_Elements_Collected collected not collected
    When_RenderTransform_Shared_By_Popup_Style_Then_Discarded_Popups_Collected passes not collected
    When_Transform_Shared_By_TransformGroups_Then_Discarded_Groups_Collected collected not collected
    When_RenderTransform_Shared_By_Style_Then_View_Is_Last_Live_Element (new guard) passes passes
    When_TransformGroup_Children_Cleared_Then_Removed_Child_Collected (guard) passes passes

    Their screenshot checks failed on native Android with and without the fix. A native-Android screenshot doesn't capture render transforms at all, not even a plain, unshared ScaleTransform (I checked with a local probe test). So 3724a5a (test(transform): Skip the image checks on native Android) skips only the image checks on native Android; the collection checks still run there. With it, all the transform tests pass on the emulator, the guards included. Given_Storyboard.When_Begin_Stop_Begin times out on the emulator with and without the fix, so it isn't related.

    iOS: not run. servicing/6.8 lacks the scene life-cycle fixes that the iOS 27 SDK needs: the SamplesApp, built with the current iOS 27 SDK, launches to a black window on the simulator, so no test runs there.

  2. Creation cost of commit 3: measured on a quiet machine, on Skia desktop and WebAssembly, and it isn't measurable. Creating, detaching and collecting are within noise of the old strong storage, and DataContext changes cost +0% to +2%.

    How I measured it:

    • Same process for both modes: a temporary switch (not part of this PR) brings back the strong storage from before commit 3, so both modes run in the same build and the same process.
    • Alternation: the modes alternate every round (ABBA), so machine load hits both equally.
    • Rounds: 3 warm-up rounds and 16 timed rounds per scenario; the table shows medians.
    • Coverage: these are single quiet runs per platform.

    The scenarios:

    • 300 default Buttons in a StackPanel;
    • a ListView with 200 items, of which 45 are realized; its template has a TextBlock, a CheckBox and a Button.

    Each round times create (including adding to the tree and layout), detach, and a full GC with finalizers, all under a non-null DataContext. A third scenario times DataContext changes on 20 loaded Buttons: 500 changes to a new view model each time, 500 changes between two view models, and 100 rounds of a new Content string on every Button (each content Run then inherits a value it has never seen).

    Weak (commit 3) vs strong storage, medians:

    Skia desktop WebAssembly (Chrome, interpreter)
    300 Buttons: create / detach / GC +3% / 0% / +1% 0% / +1% / −1%
    ListView: create / detach / GC +1% / 0% / +3% +1% / +1% / +1%
    500 DataContext changes, a new view model each time +1% +2%
    500 DataContext changes, two alternating view models +2% +2%
    new Content string on 20 Buttons, 100 times 0% +2%

    For scale, with strong storage:

    • 300 Buttons take about 90 ms to create on desktop and 920 ms on WebAssembly.
    • The 500 DataContext changes take about 14 ms on desktop and 310 ms on WebAssembly.

    The handles: a round of 300 Buttons allocates 1200 weak handles, 4 per Button: its VisualStateGroup, the groups collection, the VisualStateManager and the content Run. The ListView round allocates 1289, about 28 per realized item.

    • Why 4, not ~10: the states and their storyboards never receive the DataContext. VisualStateGroup.States is created with isAutoPropertyInheritanceEnabled: false (VisualStateGroup.cs:64), and a VisualState disables property inheritance (VisualState.cs:30) and materializes its content only when used (VisualState.cs:41).
    • Bytes: the handles add about 37 KB per round of 300 Buttons on desktop (32 bytes each) and 19 KB on WebAssembly, on top of about 44 MB and 29 MB for the round.
    • Earlier busy runs: on a busy machine I had seen detach up to 60% slower with commit 3. On the quiet machine it's 0%, so that was load.

    I also tried sharing one weak handle per inherited value, through a ConditionalWeakTable keyed on the value instead of a handle per object. It cuts the handles allocated by 75% to 93% (300 instead of 1200 for the Buttons, 90 instead of 1289 for the ListView). But it costs +5% to +10% on DataContext changes, against +0% to +2% for commit 3 as is, and it adds machinery to a servicing fix, so I left it out. I'm happy to add it if you'd rather have fewer handles. Pooling through WeakReferencePool went too, because it still allocates per object: only returned handles are reused, the pool holds at most 500, and a round of 300 Buttons takes 1200.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants