Skip to content

[MAUI 5.0.2] MapControl is not garbage collected after page navigation (SKGLView memory leak) #3271

@MereDoku

Description

@MereDoku

Mapsui Version

  • Mapsui.Maui: 5.0.2
  • Mapsui: 5.0.2

Platform(s)

  • WinUI (MAUI)
  • Android (MAUI)
  • iOS (MAUI)

Describe the bug

After navigating to a page containing Mapsui.Maui.MapControl and then leaving the page,
the page and its visual tree are correctly garbage collected, but MapControl itself and
the underlying SKGLView are not collected.

This results in a memory leak that accumulates when navigating multiple times to/from a page
containing a MapControl.

The issue is reproducible on WinUI, Android and iOS.


Steps to reproduce

  1. Clone the repro project:
    https://github.com/MereDoku/Mapsui.Maui.MemoryLeak.Repro
  2. Build and run the app (WinUI / Android / iOS)
  3. From the first page, click "Open Map Page"
  4. Navigate back
  5. Trigger VisualLeakCheckQueue.Monitor() (already wired in the repro)
  6. Observe that MapControl and SKGLView are not garbage collected

Expected behavior

After leaving the page and running GC, MapControl and SKGLView should be garbage collected.


Actual behavior

MapControl and its underlying SKGLView remain alive after page navigation, causing
a memory leak.


Leak detector output

WinUI

MapPage => ✅ Collected

Grid => ✅ Collected

    MapControl => 💦 Leak

        SKGLView => 💦 Leak

Android

[0:] MapPage => ✅ Collected
[0:] - Grid => ✅ Collected
[0:] - MapControl => 💦 Leak
[0:] - SKGLView => 💦 Leak

iOS

[0:] MapPage => ✅ Collected
[0:] - Grid => ✅ Collected
[0:] - MapControl => 💦 Leak
[0:] - SKGLView => 💦 Leak


Environment

  • .NET: MAUI (.NET version used in repro)
  • MAUI: (same as repro)
  • SkiaSharp / SkiaSharp.Views.Maui: (same as repro)

Additional context

  • The repro uses a custom weak-reference based leak detector (VisualLeakCheckQueue)
  • The leak occurs even with simple navigation and without specific user interaction
  • I created a fork and implemented fixes that resolve the leak on all three platforms
    (WinUI / Android / iOS)
  • I can open a Pull Request once we agree on the approach

Please let me know if you would like the repro simplified further (e.g. map without layers).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions