void OnObjectDeleted(RefCounted refCounted, IntPtr handle) { if (refCounted.GetType() != objectType) { return; } managedSubscribersByObjects.Remove(handle); nativeSubscriptionsForObjects.Remove(handle); }
public void Add(RefCounted refCounted) { lock (knownObjects) { ReferenceHolder<RefCounted> knownObject; if (knownObjects.TryGetValue(refCounted.Handle, out knownObject)) { var existingObj = knownObject?.Reference; if (existingObj != null && !IsInHierarchy(existingObj.GetType(), refCounted.GetType())) throw new InvalidOperationException($"Handle '{refCounted.Handle}' is in use by '{existingObj.GetType().Name}' (IsDeleted={existingObj.IsDeleted}). {refCounted.GetType()}"); } knownObjects[refCounted.Handle] = new ReferenceHolder<RefCounted>(refCounted, weak: refCounted.Refs() < 1 && !StrongRefByDefault(refCounted)); } }