Repository navigation
Use weak events for shape and geometry child collections - #38403
wbv-profile wants to merge 1 commit into
Conversation
TransformGroup, GeometryGroup, PathFigure and PathGeometry each subscribe to a child collection and to every child in it with plain CLR event handlers, unsubscribing only when the owning bindable property is replaced. A collection that outlives its owner -- shared between owners or declared in a ResourceDictionary -- therefore roots every owner it is assigned to. Each subscription now goes through the weak-event proxies in Internals/WeakEventProxy.cs, matching the pattern already used by Border and by Shape in this same folder, and each type gains the finalizer those proxies require. PathGeometry subscribes to each figure twice: PropertyChanged and the internal PathFigure.InvalidatePathSegmentRequested. Making only the first weak would leave the figure rooting the geometry, so this adds WeakPathFigureInvalidateProxy, mirroring the existing WeakGeometryChangedProxy. Existing Reset and refcount semantics are preserved; the only behavioural change is that a discarded owner no longer stays alive. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
🚀 Dogfood this PR with:
Or
|
|
Hey there @@wbv-profile! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @wbv-profile! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Worth keeping, but not ready to merge as-is. There is a regression in Please also reconcile the |
|
Following up on the review above: closing this version rather than taking the duplicate- The |
Description of Change
TransformGroup,GeometryGroup,PathFigureandPathGeometryeach subscribe to a child collection and to every child inside it using plain CLR event handlers, and only unsubscribe when the owning bindable property is replaced. ATransformCollection/GeometryCollection/PathSegmentCollection/PathFigureCollectionthat outlives its owner — shared between owners, or declared in aResourceDictionary— therefore roots every owner it is ever assigned to, along with everything those owners reference.This is the same defect and the same fix as #38397 (
GradientBrush), applied to the four remaining shape/geometry types. Each subscription now goes through the existing weak-event primitives insrc/Controls/src/Core/Internals/WeakEventProxy.cs, matching the pattern already used byBorderand byShapein this same folder, and each type gains the finalizer those proxies require.Per type:
TransformGroup.Children— collection subscription plus the refcounted per-transformPropertyChanged. The refcount dictionary now carries aWeakNotifyPropertyChangedProxyalongside the count.GeometryGroup.Children— same shape asTransformGroup.PathFigure.Segments— theList<PathSegment>of subscribed segments becomes aDictionary<PathSegment, WeakNotifyPropertyChangedProxy>;Resethandling is unchanged in behaviour.PathGeometry.Figures— subscribes to each figure twice:PropertyChangedand the internalPathFigure.InvalidatePathSegmentRequested. Making only the first weak would leave the figure still rooting the geometry, so this adds aWeakPathFigureInvalidateProxytoWeakEventProxy.cs, mirroring the existingWeakGeometryChangedProxyexactly. Both subscriptions per figure are now weak.None of these four types set
Parenton their children, so the event subscriptions are the only retention path — unlikeGradientBrush, whereGradientStop.Parentis a strong reference by design.Existing
Reset/ refcount semantics are preserved throughout; the only behavioural change is that a discarded owner no longer stays alive.Tests
src/Controls/tests/Core.UnitTests/Shapes/ShapesWeakEventTests.csadds 10 tests: one shared-collection leak test per type, plus six guards asserting that child property changes and collection changes still raise invalidation (TransformGrouprecomputing its matrix,GeometryGroup.InvalidateGeometryRequested,PathFigure.InvalidatePathSegmentRequested, andPathGeometry.InvalidatePathGeometryRequestedfor both a figure change and a segment change nested inside a figure).The guards matter: without them the four leak tests would also pass if the subscriptions had simply been dropped rather than made weak. Verified by reverting the
src/Controls/src/Corechanges and re-running — the four leak tests fail and all six guards pass. With the fix all 10 pass and the fullControls.Core.UnitTestssuite is green.Issues Fixed
The leak scanner filed each of these twice; both descriptions refer to the same collection subscription.
Fixes #37582
Fixes #37583
Fixes #37584
Fixes #37585
Fixes #38284
Fixes #38285
Fixes #38286
Fixes #38287