Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAsyncDisposable.DisposeAsync should call and await 'DisposeAsyncCore' and call 'Dispose(false)' #818

Open
RalfKoban opened this issue Mar 26, 2024 · 0 comments

Comments

@RalfKoban
Copy link
Owner

Excerpt from https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync :

The public parameterless DisposeAsync() method is called implicitly in an await using statement, and its purpose is to free unmanaged resources, perform general cleanup, and to indicate that the finalizer, if one is present, need not run.

Freeing the memory associated with a managed object is always the domain of the garbage collector. Because of this, it has a standard implementation:

public async ValueTask DisposeAsync()
{
    // Perform async cleanup.
    await DisposeAsyncCore();

    // Dispose of unmanaged resources.
    Dispose(false);

    // Suppress finalization.
    GC.SuppressFinalize(this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
MiKo Analyzers
  
Unclear
Development

No branches or pull requests

1 participant