_track disabled

This commit is contained in:
2025-12-17 01:11:12 +02:00
parent 4675fa5efc
commit 32608bac35

View File

@@ -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<IntPtr> _weakHandles = new HashSet<nint>();
private static ConcurrentDictionary<IntPtr, string> _handles = new();
private static ConcurrentDictionary<IntPtr, string> _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();
}