protected virtual void Dispose(bool disposing) { if (!disposed.TryRelaxedSet()) { return; } if (handle != null) { var tmpHandle = Interlocked.Exchange(ref handle, null); if (used > 0) { // A tiny wait (just a few cycles normally) before releasing SpinWait wait = new SpinWait(); while (used > 0) { wait.SpinOnce(); } } ((IDisposable)tmpHandle).Dispose(); } }