_track disabled
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#define USE_CONCURRENT_DICT
|
#define USE_CONCURRENT_DICT
|
||||||
#define USE_GCHANDLE
|
#define USE_GCHANDLE
|
||||||
|
//#define TRACK_HANDLES
|
||||||
|
|
||||||
#if USE_NETCORE
|
#if USE_NETCORE
|
||||||
using System;
|
using System;
|
||||||
@@ -363,19 +364,24 @@ namespace FlaxEngine.Interop
|
|||||||
#if USE_GCHANDLE
|
#if USE_GCHANDLE
|
||||||
private GCHandle handle;
|
private GCHandle handle;
|
||||||
|
|
||||||
|
#if TRACK_HANDLES
|
||||||
private static HashSet<IntPtr> _weakHandles = new HashSet<nint>();
|
private static HashSet<IntPtr> _weakHandles = new HashSet<nint>();
|
||||||
private static ConcurrentDictionary<IntPtr, string> _handles = new();
|
private static ConcurrentDictionary<IntPtr, string> _handles = new();
|
||||||
private static ConcurrentDictionary<IntPtr, string> _handles2 = new();
|
private static ConcurrentDictionary<IntPtr, string> _handles2 = new();
|
||||||
|
#endif
|
||||||
|
|
||||||
private ManagedHandle(IntPtr handle) => this.handle = GCHandle.FromIntPtr(handle);
|
private ManagedHandle(IntPtr handle) => this.handle = GCHandle.FromIntPtr(handle);
|
||||||
|
|
||||||
private ManagedHandle(object value, GCHandleType type) //=> handle = GCHandle.Alloc(value, type);
|
private ManagedHandle(object value, GCHandleType type) //=> handle = GCHandle.Alloc(value, type);
|
||||||
{
|
{
|
||||||
|
#if TRACK_HANDLES
|
||||||
if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection)
|
if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection)
|
||||||
{
|
{
|
||||||
type = GCHandleType.Normal;
|
type = GCHandleType.Normal;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
handle = GCHandle.Alloc(value, type);
|
handle = GCHandle.Alloc(value, type);
|
||||||
|
#if TRACK_HANDLES
|
||||||
if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection)
|
if (type == GCHandleType.Weak || type == GCHandleType.WeakTrackResurrection)
|
||||||
_weakHandles.Add((IntPtr)handle);
|
_weakHandles.Add((IntPtr)handle);
|
||||||
else if (_handles.Count < 14000)
|
else if (_handles.Count < 14000)
|
||||||
@@ -388,6 +394,7 @@ namespace FlaxEngine.Interop
|
|||||||
type = type;
|
type = type;
|
||||||
_handles2.TryAdd((IntPtr)handle, value?.GetType().FullName ?? "");
|
_handles2.TryAdd((IntPtr)handle, value?.GetType().FullName ?? "");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
private IntPtr handle;
|
private IntPtr handle;
|
||||||
@@ -408,6 +415,7 @@ namespace FlaxEngine.Interop
|
|||||||
{
|
{
|
||||||
if ((IntPtr)handle == IntPtr.Zero)
|
if ((IntPtr)handle == IntPtr.Zero)
|
||||||
return;
|
return;
|
||||||
|
#if TRACK_HANDLES
|
||||||
if (_weakHandles.Remove((IntPtr)handle))
|
if (_weakHandles.Remove((IntPtr)handle))
|
||||||
{
|
{
|
||||||
if (!handle.IsAllocated)
|
if (!handle.IsAllocated)
|
||||||
@@ -422,7 +430,7 @@ namespace FlaxEngine.Interop
|
|||||||
{
|
{
|
||||||
handle = handle;
|
handle = handle;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
handle.Free();
|
handle.Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user