-
-
Notifications
You must be signed in to change notification settings - Fork 348
Memory leak WinUI 3 #2259
Description
Mapsui Version
4.1.1
Mapsui Platform
WinUI 3
Device
Windows 11
Describe the bug
When you create a Mapsui map either in code or by Xaml, when disposed it does not release all resources. This is true if you use 1 or 20. It's always the same resources.
Mapsui.IFeature[] Count:1 Size(bytes):12
Mapsui.Styles.Color Count:148 Size(bytes):3552
Mapsui.Animations.Easing Count:13 Size(bytes):572
Action<Mapsui.Navigator> Count:1 Size(bytes):32
Mapsui.Map+<>c Count:1 Size(bytes):12
Mapsui.Animations.Easing+<>c Count:1 Size(bytes):12
EmptyPartition<Mapsui.Animations.AnimationEntry<Mapsui.Viewport>> Count:1 Size(bytes):12
Mapsui.Map[] Count:1 Size(bytes):12
Mapsui.Tiling.Layers.TileLayer+<>c Count:1 Size(bytes):12
EmptyPartition<Mapsui.Layers.ILayer> Count:1 Size(bytes):12
Mapsui.Fetcher.FetchWorker[] Count:1 Size(bytes):12
Mapsui.Styles.BitmapRegistry Count:1 Size(bytes):396
Total size (bytes)4648
It's not a lot, but enough to keep a page in memory and if a new page uses one, it will keep more. With WinUI 3 Navigation Template Studio template this can be brutal. It means any page that has a map UI on it, memory is not released each time you visit another page. It will not be collected until the application stops. And it will keep another page in memory if you navigate to it again. For some applications this could be a major memory leak issue.
To Reproduce
Steps to reproduce the behavior:
- In Visual Studio 2022 create a WinUI 3 project and page (you can use a blank page in Template Studio with a navigation control if you want to make it easy).
- Create two buttons in a stack panel and wire for their click events.
- create a class wide variable _Maps
- In the first button new up a map, add two layers then add to _Maps collection. For fun you could add 20 or more. The results are the same with 1 or many.
- in the second event loop through the collection and call dispose then _Maps.clear() to even remove the lists references. To make testing faster also call GC.Collect();
- Take a snapshot and then open the snapshot and search for mapsui. You'll see the list I sent. If you don't trust the GC collected (it did, wait a while. Even an hour. Then take another snapshop. Those items stay in memory the whole time.
Expected behavior
Expected behavior would be ZERO mapsui objects after calling Dispose on each map and a garbage collection.
Additional context
Why not use System.Drawing.Color instead of specific ones for Mapsui?
