private void ReleaseUnmanagedResources() { if (_disposed) { return; } var rcwCount = RdMarshal.ReleaseComObject(Interface); var addRef = _addRef; TraceRelease(rcwCount, ref addRef); if (addRef) { RdMarshal.Release(_pUnk); } _disposed = true; }
protected virtual void Dispose(bool disposing) { if (_isDisposed || !disposing) { return; } _isDisposed = true; if (WrappedObject != null) { RdMarshal.ReleaseComObject(WrappedObject); } if (_outerObject != IntPtr.Zero) { RdMarshal.Release(_outerObject); // dont set _outerObject to IntPtr.Zero here, as GetInterface() can still be called by the outer RCW // if it is still alive. For example, if ExtractWrappedObject was used and the outer object hasn't yet // been released with ReleaseComObject. In that circumstance _outerObject will still be a valid pointer // due to the internally held reference, and so GetInterface() calls past this point are still OK. } }