public void Dispose() { if (_releaser?.Release(Resource) ?? false) { return; } if (Resource is IDisposable d) { d.Dispose(); } }
public void Dispose() { if (_releaser?.Release(Resource) ?? false) { return; } // ReSharper disable once HeapView.PossibleBoxingAllocation if (Resource is IDisposable d) { d.Dispose(); } }
/// <summary> /// Releases all resources. /// </summary> protected override void Dispose(bool disposing) { if (!_closed) { if (!disposing) { Debug.WriteLine("Finalized without closing"); } base.Dispose(disposing); _closed = true; _resourceReleaser.Release(_byteArray); } }
/// <summary> /// Releases the resource specified by the given key. /// </summary> /// <typeparam name="TKey">The type of the key.</typeparam> /// <param name="key">The key.</param> /// <exception cref="System.NotSupportedException">The type of the key and/or resource is not supported by this manager.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="key" /> is null.</exception> public void Release <TKey>(TKey key) { if (key == null) { throw new ArgumentNullException(nameof(key)); } IResourceReleaser <TKey> rm = this as IResourceReleaser <TKey>; if (rm == null) { throw new NotSupportedException(Strings.ResourceManager_TypesNotSupported); } rm.Release(key); }
/// <summary> /// Decrement the reference count for the shared reference. /// If the reference count drops to zero, then dispose of the referenced value. /// </summary> public void DeleteReference() { if (DecreaseRefCount() == 0) { T deleted; lock (_referenceGate) { deleted = _value; _value = default(T); } _resourceReleaser.Release(deleted); RemoveLiveReference(deleted); } }