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

Commit

Permalink
Merge pull request #131 from Barsonax/feature/cleanuplistsinscopedisp…
Browse files Browse the repository at this point in the history
…osal

Dispose and finalizers are now properly emptied when a scope is disposed
  • Loading branch information
Barsonax committed Feb 16, 2020
2 parents e39abd5 + e3bd05c commit 5a5da5c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Singularity/Scoped.cs
Expand Up @@ -177,14 +177,14 @@ internal T AddFinalizer<T>(T obj, ServiceBinding key)
/// </summary>
public void Dispose()
{
SinglyLinkedListNode<IDisposable>? disposables = _disposables;
SinglyLinkedListNode<IDisposable>? disposables = Interlocked.Exchange(ref _disposables, null);
while (disposables != null)
{
disposables.Value.Dispose();
disposables = disposables.Next!;
}

SinglyLinkedListKeyNode<ServiceBinding, ActionList<object>>? finalizers = _finalizers;
SinglyLinkedListKeyNode<ServiceBinding, ActionList<object>>? finalizers = Interlocked.Exchange(ref _finalizers, null);;
while (finalizers != null)
{
finalizers.Value.Invoke();
Expand Down

0 comments on commit 5a5da5c

Please sign in to comment.