public static void Dispose <T>(this NativeMap <T> map, ref IntPtr ptr) where T : class { if (ptr != IntPtr.Zero) { map.TryRemove(ptr, out var dummy); } ptr = IntPtr.Zero; }