Ensure cached pointer wrappers are cleaned up when deleted

This commit is contained in:
Deukhoofd 2020-05-19 13:14:05 +02:00
parent 95a2270ca3
commit 2c94f6ab50
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 6 additions and 0 deletions

View File

@ -30,6 +30,12 @@ namespace PkmnLibSharp.Utilities
Cached.TryAdd(ptr, weakRef); Cached.TryAdd(ptr, weakRef);
} }
~PointerWrapper()
{
if (!_isDeleted)
Cached.TryRemove(Ptr, out _);
}
public static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper public static bool TryResolvePointer<T>(IntPtr p, out T result) where T : PointerWrapper
{ {
if (Cached.TryGetValue(p, out var val)) if (Cached.TryGetValue(p, out var val))