Skip to content

PathGeometry.Figures.Clear() leaks when clearing shared PathFigure instances #35809

Description

@AdamEssenmacher

Description

PathGeometry.Figures.Clear() does not appear to unsubscribe cleared PathFigure instances from the owning PathGeometry. If a PathFigure is shared/rooted elsewhere, the cleared figure can retain the page-local PathGeometry, which then retains the Path through InvalidatePathGeometryRequested, and the Path retains its BindingContext.

Repro project:

https://github.com/AdamEssenmacher/maui/tree/repro/pathgeometry-figures-clear-leak/src/Controls/samples/PathGeometryFiguresClearLeakRepro

Leak path shown by the repro:

shared PathFigure -> PropertyChanged delegate -> page-local PathGeometry -> InvalidatePathGeometryRequested delegate -> Path -> BindingContext payload

The repro runs three scenarios:

control:
  page-local PathFigure + PathGeometry.Figures.Clear()

leaky:
  shared/rooted PathFigure + PathGeometry.Figures.Clear()

mitigation:
  shared/rooted PathFigure + PathGeometry.Figures.RemoveAt(0)

Observed on iOS simulator:

control:
  Payload view models retained: 0/50
  Paths retained: 0/1200
  PathGeometry instances retained: 0/1200

leaky:
  Payload view models retained: 50/50
  Paths retained: 1200/1200
  PathGeometry instances retained: 1200/1200
  Retained payload bytes: 209715200 (200.00 MiB)

mitigation:
  Payload view models retained: 0/50
  Paths retained: 0/1200
  PathGeometry instances retained: 0/1200

Expected behavior: Figures.Clear() should unsubscribe removed figures the same way indexed removal does, allowing the page-local PathGeometry, Path, and payload graph to be collected.

Steps to Reproduce

  1. Clone the repro branch:
git clone --branch repro/pathgeometry-figures-clear-leak https://github.com/AdamEssenmacher/maui.git maui-pathgeometry-repro
cd maui-pathgeometry-repro

Repro project:
https://github.com/AdamEssenmacher/maui/tree/repro/pathgeometry-figures-clear-leak/src/Controls/samples/PathGeometryFiguresClearLeakRepro

  1. Build MAUI build tasks:
dotnet build Microsoft.Maui.BuildTasks.slnf
  1. Build the repro app for an iOS simulator:
dotnet build src/Controls/samples/PathGeometryFiguresClearLeakRepro/PathGeometryFiguresClearLeakRepro.csproj \
  -f net10.0-ios \
  -p:RuntimeIdentifier=iossimulator-arm64
  1. Pick and boot an iOS simulator:
xcrun simctl list devices available
UDID=<simulator-udid>
xcrun simctl boot "$UDID"
xcrun simctl bootstatus "$UDID"
  1. Install and launch the autorun repro:
xcrun simctl install "$UDID" \
  artifacts/bin/PathGeometryFiguresClearLeakRepro/Debug/net10.0-ios/iossimulator-arm64/PathGeometryFiguresClearLeakRepro.app

xcrun simctl launch --terminate-running-process "$UDID" \
  com.microsoft.maui.pathgeometryfiguresclearleakrepro \
  --auto-run --target=PathGeometryFigures
  1. Read the generated report:
APP_CONTAINER=$(xcrun simctl get_app_container "$UDID" com.microsoft.maui.pathgeometryfiguresclearleakrepro data)

cat "$APP_CONTAINER/Library/PathGeometryFiguresClearLeakRepro/autorun-results.txt"

Expected Result

control, leaky, and mitigation should all release popped page payloads, Path controls, and page-local PathGeometry instances after forced full GC.

Actual Result

Only the shared PathFigure + PathGeometry.Figures.Clear() scenario retains the payload graph:

shared PathFigure -> PropertyChanged delegate -> page-local PathGeometry -> InvalidatePathGeometryRequested delegate -> Path -> BindingContext payload

Observed result:

control:
  Payload view models retained: 0/50
  Paths retained: 0/1200
  PathGeometry instances retained: 0/1200

leaky:
  Payload view models retained: 50/50
  Paths retained: 1200/1200
  PathGeometry instances retained: 1200/1200
  Retained payload bytes: 209715200 (200.00 MiB)

mitigation:
  Payload view models retained: 0/50
  Paths retained: 0/1200
  PathGeometry instances retained: 0/1200

Link to public reproduction project repository

https://github.com/AdamEssenmacher/maui/tree/repro/pathgeometry-figures-clear-leak/src/Controls/samples/PathGeometryFiguresClearLeakRepro

Version with bug

10.0.70

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Activity

  1. added
    t/bug
    on Jun 8, 2026
  2. added
    area-drawing
    on Jun 8, 2026
  3. NafeelaNazhir commented on Jun 9, 2026

    @NafeelaNazhir
    Contributor

    This issue has been validated in Visual Studio Code 1.123.0 with .NET MAUI versions 9.0.0, 10.0.0 & 10.0.70. It was reproducible on iOS, Android platform.

    Screen.Recording.2026-06-09.at.11.45.46.AM.mov
    Screen.Recording.2026-06-09.at.11.42.40.AM.mov
  4. added
    s/triaged
    s/verified
    on Jun 9, 2026
  5. added this to the Backlog milestone on Jun 9, 2026
  6. added
    partner/syncfusion
    on Jun 11, 2026
  7. added a commit that references this issue on Aug 10, 2026
  8. locked and limited conversation to collaborators on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-drawingpartner/syncfusionplatform/androidplatform/ioss/triageds/verifiedt/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions