public virtual IReplica?TryGet(PublicationRef publicationRef) { var random = publicationRef.PublicationId.HashCode; OnOperation(random); if (!_handles.TryGetValue(publicationRef, out var handle)) { return(null); } var target = (IReplica?)handle.Target; if (target != null) { return(target); } // GCHandle target == null => we have to recycle it if (!_handles.TryRemove(publicationRef, handle)) { // Some other thread already removed this entry return(null); } // The thread that succeeds in removal releases gcHandle as well _gcHandlePool.Release(handle, random); return(null); }
public virtual IComputed?TryGet(ComputedInput key) { var random = Randomize(key.HashCode); OnOperation(random); if (_storage.TryGetValue(key, out var handle)) { var value = (IComputed?)handle.Target; if (value != null) { return(value); } if (_storage.TryRemove(key, handle)) { _gcHandlePool.Release(handle, random); } } return(null); }
// プール経由で開放する public void Dispose() { GCHandlePool.Release(handle); handle = default; }