From 783315bbad4623d03f5f4887b05efcca1c35387d Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Tue, 9 Jul 2024 17:08:28 +0200 Subject: [PATCH 1/2] [GL] fixed memory leak caused by missing onMakeCurrent callbacks when ContextHandle is disposed (destroy of UnsharedObjects/Framebuffer) --- src/Aardvark.Rendering.GL/Core/ContextHandles.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Aardvark.Rendering.GL/Core/ContextHandles.fs b/src/Aardvark.Rendering.GL/Core/ContextHandles.fs index dc8957e24..e2419562e 100644 --- a/src/Aardvark.Rendering.GL/Core/ContextHandles.fs +++ b/src/Aardvark.Rendering.GL/Core/ContextHandles.fs @@ -86,6 +86,7 @@ type ContextHandle(handle : IGraphicsContext, window : IWindowInfo) = (handle |> unbox).GetAddress(name) member x.OnMakeCurrent(f : unit -> unit) = + if isDisposed then failwith "Failed to register OnMakeCurrent callback, the context is already disposed!" Interlocked.CompareExchange(&onMakeCurrent, ConcurrentHashSet(), null) |> ignore onMakeCurrent.Add f |> ignore @@ -214,6 +215,15 @@ type ContextHandle(handle : IGraphicsContext, window : IWindowInfo) = if lockTaken then if not isDisposed then + + // release potentially pending UnsharedObjects + let actions = Interlocked.Exchange(&onMakeCurrent, null) + if actions <> null then + x.Use(fun () -> + for a in actions do + a() + ) + isDisposed <- true debugOutput |> Option.iter (fun dbg -> dbg.Dispose()) onDisposed.Trigger() From c70611cf742e2c2ceec321dee6475ca65b3a2889 Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Wed, 10 Jul 2024 17:50:09 +0200 Subject: [PATCH 2/2] updated RELEASE_NOTES.md --- RELEASE_NOTES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index cf4910254..72bc2592e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,8 @@ +### 5.4.12 +- [GL] Fixed potential memory leak after ContextHandle is disposed +- Optimized generic dispatch +- Fixed potential leaks with ConcurrentDictionary.GetOrAdd + ### 5.4.11 - [Application.WPF.GL] SharingRenderControl implementation now uses Silk.NET.Direct3D9 instead of SharpDX - Removed SharpDX dependency