public void Dispose() { if (!m_Disposer.IsDisposed) { m_Disposer.Dispose(); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing) { var handler = CurrentScopeEnding; if (handler != null) { handler(this, new LifetimeScopeEndingEventArgs(this)); } _disposer.Dispose(); } base.Dispose(disposing); }
/// <summary> /// Decreases reference counter. Must not be used outside of SharedHandle or SharedDisposableObject. /// </summary> internal void unuse(bool callFromFinalizer) { TType objectToDestroy = null; lock (this) { CheckAccess(); refCount--; if (refCount <= 0) { // It means, that now object is being destroyed and access should be locked refCount = -1; // Keep reference to call destructor outside of synchronization block // thus avoiding possible deadlocks objectToDestroy = referent; referent = null; } } // If we are here with intention to dispose the controlled object // and the call is made from the finalizer then it means that it was the last // reference to the controlled object, so it is also marked for garbage collection // and we have no guarantee that it has not been garbage collected already. // So we have to ignore disposal in such cases (the controlled object itself // has to provide correct logic to release resources when being finalized) if ((objectToDestroy != null) && !callFromFinalizer) { try { disposer.Dispose(objectToDestroy); } catch (Exception ex) { Log.DebugFormat(GetType(), "Exception during object disposal: {0}", ex.Message); } } }