From e3bd05c9cb76b89ae8d7dcd298eb202173081c0c Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Sun, 16 Feb 2020 21:25:27 +0100 Subject: [PATCH] dispose and finalizers are now properly emptied when a scope is disposed --- src/Singularity/Scoped.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Singularity/Scoped.cs b/src/Singularity/Scoped.cs index 16d35ec..dc9a9ec 100644 --- a/src/Singularity/Scoped.cs +++ b/src/Singularity/Scoped.cs @@ -177,14 +177,14 @@ internal T AddFinalizer(T obj, ServiceBinding key) /// public void Dispose() { - SinglyLinkedListNode? disposables = _disposables; + SinglyLinkedListNode? disposables = Interlocked.Exchange(ref _disposables, null); while (disposables != null) { disposables.Value.Dispose(); disposables = disposables.Next!; } - SinglyLinkedListKeyNode>? finalizers = _finalizers; + SinglyLinkedListKeyNode>? finalizers = Interlocked.Exchange(ref _finalizers, null);; while (finalizers != null) { finalizers.Value.Invoke();