private static void Free(NetMsg *msg) { var ptr = msg->DataPtr; lock ( ReferenceCounters ) { if (!ReferenceCounters.TryGetValue(ptr, out var counter)) { SteamNetworkingUtils.LogDebugMessage(NetDebugOutput.Bug, $"Attempt to free pointer not tracked by {nameof(BufferManager)}: {ptr.ToInt64():X8}"); return; } #if DEBUG SteamNetworkingUtils.LogDebugMessage(NetDebugOutput.Verbose, $"{nameof( BufferManager )} decrementing reference count of {ptr.ToInt64():X8}"); #endif if (counter.Decrement()) { #if DEBUG SteamNetworkingUtils.LogDebugMessage(NetDebugOutput.Verbose, $"{nameof( BufferManager )} freeing {ptr.ToInt64():X8} as it is now unreferenced"); if (ptr != counter.Pointer) { SteamNetworkingUtils.LogDebugMessage(NetDebugOutput.Bug, $"{nameof( BufferManager )} freed pointer ({ptr.ToInt64():X8}) does not match counter pointer ({counter.Pointer.ToInt64():X8})"); } var bucketSize = GetBucketSize(counter.Size); if (counter.Size != bucketSize) { SteamNetworkingUtils.LogDebugMessage(NetDebugOutput.Bug, $"{nameof( BufferManager )} freed pointer size ({counter.Size}) does not match bucket size ({bucketSize})"); } #endif ReferenceCounters.Remove(ptr); FreeBuffer(ptr, counter.Size); FreeReferenceCounter(counter); } } }
internal static unsafe extern void InternalRelease(NetMsg *self);