diff --git a/src/R3/Subject.cs b/src/R3/Subject.cs index fd021cb..68e4c7e 100644 --- a/src/R3/Subject.cs +++ b/src/R3/Subject.cs @@ -231,13 +231,19 @@ void ThrowIfDisposed() } public void Dispose() + { + Dispose(true); + } + + public void Dispose(bool callOnCompleted) { if (completeState.TrySetDisposed(out var alreadyCompleted)) { - if (!alreadyCompleted) + if (!alreadyCompleted && callOnCompleted) { var currentVersion = GetVersion(); var node = root; + Volatile.Write(ref root, null); while (node != null) { if (node.Version > currentVersion) break; @@ -245,6 +251,10 @@ public void Dispose() node = node.Next; } } + else + { + Volatile.Write(ref root, null); + } } }