From 95041d4ff9e4177de183792f7e3cd80c11f49665 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 01:11:12 +0200 Subject: [PATCH] _track disabled --- Source/Engine/Engine/NativeInterop.Managed.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Engine/NativeInterop.Managed.cs b/Source/Engine/Engine/NativeInterop.Managed.cs index b91a98ed4..9d9a7f63f 100644 --- a/Source/Engine/Engine/NativeInterop.Managed.cs +++ b/Source/Engine/Engine/NativeInterop.Managed.cs @@ -2,6 +2,7 @@ #define USE_CONCURRENT_DICT #define USE_GCHANDLE +//#define TRACK_HANDLES #if USE_NETCORE using System; @@ -363,19 +364,24 @@ namespace FlaxEngine.Interop #if USE_GCHANDLE private GCHandle handle; +#if TRACK_HANDLES private static HashSet _weakHandles = new HashSet(); private static ConcurrentDictionary _handles = new(); private static ConcurrentDictionary _handles2 = new(); +#endif private ManagedHandle(IntPtr handle) => this.handle = GCHandle.FromIntPtr(handle); private ManagedHandle(object value, GCHandleType type) //=> handle = GCHandle.Alloc(value, type); { +#if TRACK_HANDLES if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection) { type = GCHandleType.Normal; } +#endif handle = GCHandle.Alloc(value, type); +#if TRACK_HANDLES if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection) _weakHandles.Add((IntPtr)handle); else if (_handles.Count < 14000) @@ -388,6 +394,7 @@ namespace FlaxEngine.Interop type = type; _handles2.TryAdd((IntPtr)handle, value?.GetType().FullName ?? ""); } +#endif } #else private IntPtr handle; @@ -408,6 +415,7 @@ namespace FlaxEngine.Interop { if ((IntPtr)handle == IntPtr.Zero) return; +#if TRACK_HANDLES if (_weakHandles.Remove((IntPtr)handle)) { if (!handle.IsAllocated) @@ -422,7 +430,7 @@ namespace FlaxEngine.Interop { handle = handle; } - +#endif handle.Free(); }