From 9d8aa631407cb8fdcb2ed29d68d5e53ff4eed9b7 Mon Sep 17 00:00:00 2001 From: EikeB89 <53081495+EikeB89@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:01:45 +0100 Subject: [PATCH 1/2] Unsubscribe OnCurrentPositionChanged to prevent Memory Leak In Constructor the OnCurrentPositionChanged event of _core is subscribed. But this subscription is never deleted, even when the control is disposed. This can lead to memory leaks and should be fixed. --- GMap.NET/GMap.NET.WindowsPresentation/GMapControl.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GMap.NET/GMap.NET.WindowsPresentation/GMapControl.cs b/GMap.NET/GMap.NET.WindowsPresentation/GMapControl.cs index cb42681c..1ce2e6e7 100644 --- a/GMap.NET/GMap.NET.WindowsPresentation/GMapControl.cs +++ b/GMap.NET/GMap.NET.WindowsPresentation/GMapControl.cs @@ -2850,6 +2850,7 @@ public virtual void Dispose() if (_core.IsStarted) { _core.OnMapZoomChanged -= ForceUpdateOverlays; + _core.OnCurrentPositionChanged -= CoreOnCurrentPositionChanged; Loaded -= GMapControl_Loaded; Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted; SizeChanged -= GMapControl_SizeChanged; From 96d3e327f2140eaaf4689d4fcbd93bf34c2b4c87 Mon Sep 17 00:00:00 2001 From: EikeB89 <53081495+EikeB89@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:11:59 +0100 Subject: [PATCH 2/2] Fixed potential memory leak for avalonia --- GMap.NET/GMap.NET.Avalonia/GMapControl.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GMap.NET/GMap.NET.Avalonia/GMapControl.cs b/GMap.NET/GMap.NET.Avalonia/GMapControl.cs index 2a8f0231..bcf9baf6 100644 --- a/GMap.NET/GMap.NET.Avalonia/GMapControl.cs +++ b/GMap.NET/GMap.NET.Avalonia/GMapControl.cs @@ -2269,6 +2269,7 @@ public virtual void Dispose() if (_core.IsStarted) { _core.OnMapZoomChanged -= ForceUpdateOverlays; + _core.OnCurrentPositionChanged -= CoreOnCurrentPositionChanged; _core.OnMapClose(); } }