Repository navigation
Fix PathFigure memory leak with shared PathSegmentCollection #38744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,30 @@ static WeakReference CreatePathWithBoth(PathGeometry geometry, ScaleTransform tr | |
| return new WeakReference(path); | ||
| } | ||
|
|
||
| static WeakReference CreatePathFigureWithSegments(PathSegmentCollection segments) | ||
| { | ||
| var figure = new PathFigure { Segments = segments }; | ||
| return new WeakReference(figure); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SharedPathSegmentCollection_DoesNotKeepPathFigureAlive() | ||
| { | ||
| var sharedSegments = new PathSegmentCollection(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
[major] Regression Prevention and Test Coverage — This regression test uses an empty |
||
|
|
||
| var figureRef = CreatePathFigureWithSegments(sharedSegments); | ||
|
|
||
| GC.Collect(); | ||
| GC.WaitForPendingFinalizers(); | ||
| GC.Collect(); | ||
|
|
||
| Assert.False(figureRef.IsAlive, | ||
| "PathFigure was not collected. The shared PathSegmentCollection is holding a strong " + | ||
| "reference to PathFigure via its CollectionChanged event handler."); | ||
|
|
||
| GC.KeepAlive(sharedSegments); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SharedPathGeometry_DoesNotKeepPathAlive() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[major] Memory Leak Prevention — The finalizer only unsubscribes the collection-level weak proxy, but it never detaches
PathSegment.PropertyChangedhandlers tracked in_subscribedSegments. Concrete failure: ifSegmentscontains one or more rooted segments (shared collection), each segment keeps a strong delegate toPathFigure, soPathFigurestays alive and this finalizer never runs.