Repository navigation
Fix PathGeometry leak with shared PathFigureCollection - #38946
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38946Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38946" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@SyedAbdulAzeemSF4852 — new AI review results are available based on commit
d35259b.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: ANDROID · Base: inflight/current · Merge base: 05da51bc
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 PathGeometryTests PathGeometryTests |
✅ FAIL — 102s | ✅ PASS — 85s |
🔴 Without fix — 🧪 PathGeometryTests: FAIL ✅ · 102s
Error-relevant lines (filtered from the build log):
at Microsoft.Maui.Controls.Core.UnitTests.Shapes.PathGeometryTests.SharedFiguresDoesNotRetainPathGeometry() in /_/src/Controls/tests/Core.UnitTests/Shapes/PathGeometryTests.cs:line 18
🟢 With fix — 🧪 PathGeometryTests: PASS ✅ · 85s
Determining projects to restore...
All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.2 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.16] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.46] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.48] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.63] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed FiguresClear_AllowsPathGeometryToBeGarbageCollected [43 ms]
Passed FiguresClear_UnsubscribesFigurePropertyChangedHandler [6 ms]
Passed FiguresClear_UnsubscribesFigureSegmentInvalidateHandler [1 ms]
Passed SharedFiguresDoesNotRetainPathGeometry [27 ms]
Test Run Successful.
Total tests: 4
Passed: 4
Total time: 2.1781 Seconds
📁 Fix files reverted (1 files)
src/Controls/src/Core/Shapes/PathGeometry.cs
📋 Pre-Flight — Context & Validation
PR #38946 Pre-Flight
Scope
- Working title: Fix PathGeometry retention by shared Figures collection
- Local branch:
pr-review-38946 - Target/base:
inflight/current - Merge base:
05da51bc679c01a0644e63702d6ffa9616639cc5 - PR commit:
d35259b86ea180f230954b36bdeac1b03417a65c - Platform requested for testing: Android
- GitHub CLI authentication was unavailable, so issue/PR narrative context could not be fetched. This summary uses the materialized PR branch, commit, diff, and gate artifacts.
Problem
PathGeometry.UpdatePathFigureCollection strongly subscribes the geometry's
OnPathFigureCollectionChanged instance handler to
PathFigureCollection.CollectionChanged. When an application shares and keeps
the collection alive after the geometry becomes unreachable, the collection's
delegate retains the PathGeometry.
The existing Reset handling already tracks individual PathFigure
subscriptions and correctly detaches them after Figures.Clear(). The new
failure is distinct: the collection itself retains the geometry even when no
figure-level subscription is involved.
Existing PR Fix
The production diff changes only
src/Controls/src/Core/Shapes/PathGeometry.cs:
- stores a
WeakNotifyCollectionChangedProxyand cached
NotifyCollectionChangedEventHandler; - subscribes the shared collection through the weak proxy rather than directly;
- unsubscribes the proxy when
Figureschanges; and - adds a
PathGeometryfinalizer that unsubscribes the proxy.
The test diff adds
SharedFiguresDoesNotRetainPathGeometry to
src/Controls/tests/Core.UnitTests/Shapes/PathGeometryTests.cs.
Gate Evidence
The completed gate passed and must not be rerun:
- without the production fix,
SharedFiguresDoesNotRetainPathGeometryfailed; - with the PR fix, all four
PathGeometryTestspassed; - the three mandatory regressions are:
FiguresClear_UnsubscribesFigurePropertyChangedHandlerFiguresClear_UnsubscribesFigureSegmentInvalidateHandlerFiguresClear_AllowsPathGeometryToBeGarbageCollected
Bounded Candidate Test
Run only the detected test class, which includes the primary reproduction and
all three mandatory regressions:
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~Microsoft.Maui.Controls.Core.UnitTests.Shapes.PathGeometryTests"Try-Fix Boundary
EstablishBrokenBaseline.ps1 is expected to allow modifications only to:
src/Controls/src/Core/Shapes/PathGeometry.cs
Each candidate must preserve the committed test change, avoid the PR's weak
proxy/finalizer mechanism, run one implementation/test pass with at most one
focused correction/retest, perform the inline expert self-review required by
the try-fix skill, capture artifacts, and restore via
EstablishBrokenBaseline.ps1 -Restore.
🔬 Code Review — Deep Analysis
Code Review — PR #38946
Independent Assessment
What this changes: Replaces PathGeometry's strong subscription to PathFigureCollection.CollectionChanged with WeakNotifyCollectionChangedProxy, caches the delegate so it remains alive while the geometry is alive, deterministically switches the proxy when Figures changes, and unsubscribes the proxy during finalization. The added regression test roots a shared collection while verifying that its former geometry can be collected.
Inferred motivation: A long-lived shared PathFigureCollection currently retains a discarded PathGeometry through the collection's event delegate.
Approach assessment: Sound and consistent with the existing PathFigure, TransformGroup, GeometryGroup, and WeakNotifyCollectionChangedProxy patterns. The cached handler is necessary because the proxy stores only a weak reference to it. The finalizer prevents the proxy instance itself from remaining registered after its target is collected.
Reconciliation with PR Narrative
Author claims: The shared collection strongly retains PathGeometry; the PR introduces the weak proxy, deterministic collection-switch unsubscription, finalizer cleanup, and a regression test.
Agreement/disagreement: The submitted diff supports those claims. It does not change the existing figure-level subscription behavior, and the description does not claim that it does.
Prior Review Reconciliation
No prior ❌ Error findings found across top-level reviews, inline review comments, or PR issue comments.
Blast Radius Assessment
- Runs for all instances: The proxy is used for every non-null
Figurescollection, preserving the same collection-change callback behavior through weak indirection. - Startup impact: None; the code runs only when a
PathGeometryassignsFigures. - Static/shared state: None added.
- Null/default behavior: A null
Figuresvalue leaves no collection proxy subscribed, matching the existing behavior.
CI Status
- Required-check result: Pending/undetermined. Anonymous check-run retrieval shows successful build/unit-test jobs and many still-running integration, device, and UI jobs;
gh pr checks --requiredcould not identify the required subset because GitHub CLI authentication is unavailable. - Classification: General CI is still in progress. The trusted task-specific Gate passed: the new test fails without the production fix and all four focused
PathGeometryTestspass with it. - Action taken: No CI re-investigation or Gate rerun; confidence is capped while general CI remains pending.
Findings
No actionable inline findings. The expert reviewer wrote an empty JSON array to inline-findings.json.
Failure-Mode Probing
- Replacing
Figuresrepeatedly:WeakNotifyCollectionChangedProxy.Subscribedetaches from its prior source, while the explicit old-collection path also unsubscribes before attaching the new collection; subscriptions do not accumulate. - Assigning null after a collection: the proxy and all tracked figure handlers are detached before the null early return.
- Collection changes after the geometry is collected: the cached delegate is collectible with the geometry; if the proxy receives an event before finalizer cleanup completes, it finds no handler and unsubscribes itself.
- Existing figure mutation and
Clear()behavior: unchanged; the trusted focused Gate includes the three pre-existing figure-subscription regressions.
External Output Contract
Not applicable.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The submitted code is internally sound, follows established MAUI weak-event patterns, has a discriminating regression test, and received no expert findings. The code-review verdict is held at NEEDS_DISCUSSION only because required-check status cannot yet be established while general CI is still running; there is no identified code change to request.
🛠️ Try-Fix — Analysis & Comparison
Alternative Fix Candidates for PR #38946
Candidate 1 — Static Dispatcher with Weak Subscriber Registry
Model: gpt-5.3-codex
Result: PASS
Detailed report: ../try-fix-1/content.md
Artifacts: attempt-1
The candidate replaces the collection's instance delegate with a static
dispatcher and stores geometries as weak references in collection-scoped state
held by a ConditionalWeakTable. This is mechanism-level distinct from the
PR's per-geometry weak proxy and finalizer. The first bounded test pass ran the
four PathGeometryTests; all 4 passed, with 0 inline self-review findings, and
the baseline restore completed with Restored True.
Candidate 2
No Safe Distinct In-File Topology
Model: gpt-5.6-sol
Result: BLOCKED
Detailed report: ../try-fix-2/content.md
Artifacts: attempt-2
No code was changed and no test was run. Collection changes must remain
observed to preserve invalidation and per-figure subscriptions. A
per-subscriber weak intermediary would duplicate the PR; shared static weak
routing would duplicate candidate 1; direct subscription retains the geometry;
and removing observation breaks behavior. A genuinely different mechanism
would require an event-source change outside the allowed PathGeometry.cs
baseline boundary. The inline no-diff self-review recorded 0 findings, and the
baseline restore completed with Restored True.
Aggregate Outcome
Exactly two sequential try-fix invocations were completed. Candidate 1 is a
tested passing alternative (4/4 targeted tests); candidate 2 is a documented
blocked exploration rather than a duplicate implementation. No candidate
changes remain applied to the worktree.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr
The submitted PR is the strongest candidate. It fixes the exact strong event-delegate path with the repository's established WeakNotifyCollectionChangedProxy pattern, preserves deterministic collection-switch cleanup, adds the required finalizer cleanup for the proxy, and includes a discriminating regression test. The trusted Gate proves the test fails without the production fix and that all four focused PathGeometryTests pass with it. The one permitted MAUI expert review produced no inline findings.
The recommendation is held at REQUEST CHANGES only because current required-check coverage is undetermined: anonymous check-run evidence shows successful build and unit-test jobs, but many integration, device, and UI jobs remain in progress, while unauthenticated gh pr checks --required cannot identify the required subset. There is no code change requested by this review; the raw PR remains the winning implementation.
Candidate Comparison
| Rank | Candidate | Regression evidence | Expert/reviewer result | Comparative assessment |
|---|---|---|---|---|
| 1 | pr |
PASS — reproduction fails without the fix; 4/4 focused tests pass with it | No actionable findings | Best balance of correctness, established MAUI precedent, localized state, and maintainability. |
| 2 | pr-plus-reviewer |
PASS (inherited) — byte-for-byte equivalent to pr; no reviewer patch existed to retest |
No actionable findings; reviewer.patch is empty |
Functionally tied with pr, but it provides no refinement, so the submitted candidate wins the tie. |
| 3 | try-fix-1 |
PASS — 4/4 focused tests | Self-review clean | Correct alternative, but the static ConditionalWeakTable dispatcher adds global shared routing, a custom weak-subscriber registry, and a temporary List<PathGeometry> allocation on every collection notification. It is substantially more complex than the existing weak-proxy abstraction and can leave an empty static handler/state attached after dead subscribers are pruned during dispatch. |
| 4 | try-fix-2 |
BLOCKED — 0 tests, no diff | No-diff self-review clean | Not a runnable candidate. Its analysis correctly concludes that another distinct safe topology would require expanding the allowed change boundary. |
Why pr Wins
- Verified behavior: It passes the primary leak reproduction and every mandatory regression; no candidate with stronger test evidence exists.
- Repository consistency:
PathFigure,TransformGroup,GeometryGroup, and other Controls types already use the same weak-proxy/finalizer pattern. - Smaller blast radius: State remains per
PathGeometry; there is no new static registry or collection-wide dispatcher. - Clear lifecycle: Reassigning or nulling
Figuresunsubscribes the old proxy and figure handlers, while finalization removes a stale proxy subscription if normal reassignment never occurs. - No expert refinement needed:
inline-findings.jsonis[], makingpr-plus-reviewerintentionally identical rather than a distinct improvement.
Residual Uncertainty
General CI was still running when this report was finalized. Per the execution contract, no additional waiting, full-suite run, or iterative candidate refinement was performed.
📱 UI Tests — Shape
Detected UI test categories: Shape
✅ Deep UI tests — 61 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Shape |
61/61 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Issue Details - PathFigureCollection keeps a strong reference to the discarded PathGeometry through its CollectionChanged handler, preventing garbage collection and resulting in a memory leak. ### Root Cause - PathGeometry subscribed directly to PathFigureCollection.CollectionChanged, allowing a shared collection to strongly retain the geometry through its event delegate. ### Description of Change - Replaced the strong collection event subscription with WeakNotifyCollectionChangedProxy, retained deterministic unsubscription when Figures changes, added finalizer cleanup, and added a regression test verifying that a shared collection does not retain PathGeometry. ### Issues Fixed Fixes #38686 ### Validated the behaviour in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Platform | Before | After | |----------|----------|----------| | iOS | <img src="https://github.com/user-attachments/assets/fb3c32f9-6b9e-4ea0-a28c-4dead1946bbc"> | <img src="https://github.com/user-attachments/assets/184f5f15-8780-4b82-a9af-da602f7812d5"> | | Android | <img src="https://github.com/user-attachments/assets/d207a69b-65aa-4fc7-8670-3b23a9fb951e"> | <img src="https://github.com/user-attachments/assets/700261b7-51f1-427e-acdf-86fa23fd78a3"> | | Mac | <img src="https://github.com/user-attachments/assets/eadd0622-cb53-43ba-a3a5-760685d16b3e"> | <img src="https://github.com/user-attachments/assets/7ea16dab-0f13-4fe1-ba70-0e80fcbd4dbb"> | | Windows | <img src="https://github.com/user-attachments/assets/fafec7fd-0036-4d21-9f64-85f614cf3e02"> | <img src="https://github.com/user-attachments/assets/f55e9e6a-2807-4e9a-8076-6691b2ad07fc"> |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
Root Cause
Description of Change
Issues Fixed
Fixes #38686
Validated the behaviour in the following platforms
Output