Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit e3bd05c

Browse files
committed
dispose and finalizers are now properly emptied when a scope is disposed
1 parent e39abd5 commit e3bd05c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Singularity/Scoped.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ internal T AddFinalizer<T>(T obj, ServiceBinding key)
177177
/// </summary>
178178
public void Dispose()
179179
{
180-
SinglyLinkedListNode<IDisposable>? disposables = _disposables;
180+
SinglyLinkedListNode<IDisposable>? disposables = Interlocked.Exchange(ref _disposables, null);
181181
while (disposables != null)
182182
{
183183
disposables.Value.Dispose();
184184
disposables = disposables.Next!;
185185
}
186186

187-
SinglyLinkedListKeyNode<ServiceBinding, ActionList<object>>? finalizers = _finalizers;
187+
SinglyLinkedListKeyNode<ServiceBinding, ActionList<object>>? finalizers = Interlocked.Exchange(ref _finalizers, null);;
188188
while (finalizers != null)
189189
{
190190
finalizers.Value.Invoke();

0 commit comments

Comments
 (0)