Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

The documentation incorrectly showed Dispose(false) being called from DisposeAsync(). This is unnecessary—DisposeAsync() is not a finalizer context, and all cleanup is already handled in DisposeAsyncCore().

Changes

  • implementing-disposeasync.md: Removed Dispose(false) call and explanatory NOTE from example; added missing .ConfigureAwait(false)
  • ExampleConjunctiveDisposable.cs: Removed Dispose(false) call from DisposeAsync() implementation

Correct Pattern

public async ValueTask DisposeAsync()
{
    await DisposeAsyncCore().ConfigureAwait(false);
    GC.SuppressFinalize(this);
}

The Dispose(bool disposing) pattern belongs to synchronous disposal with finalizers, not async disposal.

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement both dispose and async dispose patterns: Dispose(false) from DisposeAsync() is not necessary</issue_title>
<issue_description>### Type of issue

Typo

Description

• Dispose(bool disposing) is called with true when the object is being disposed explicitly (by user code), and with false when called from a finalizer (to clean up unmanaged resources only).
• In the async dispose pattern, DisposeAsync() should call DisposeAsyncCore() to asynchronously release resources, then suppress finalization.
• There is no need to call Dispose(false) from DisposeAsync(), because:
• You are not in a finalizer.
• All resource cleanup should already be handled in DisposeAsyncCore().

The correct pattern for IAsyncDisposable is:

public async ValueTask DisposeAsync() { await DisposeAsyncCore().ConfigureAwait(false); GC.SuppressFinalize(this); }

Page URL

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

Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/garbage-collection/implementing-disposeasync.md

Document Version Independent Id

d72276e1-9059-815f-dc14-a03a7544ab87

Platform Id

cc69165e-7f9b-8c59-0b79-2ba09c791e8e

Article author

@IEvangelist

Metadata

  • ID: 61a961dc-3ebf-2a96-a6eb-2e0b62ab909f
  • PlatformId: cc69165e-7f9b-8c59-0b79-2ba09c791e8e
  • Service: dotnet-fundamentals

Related Issues</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Internal previews

📄 File 🔗 Preview link
docs/standard/garbage-collection/implementing-disposeasync.md docs/standard/garbage-collection/implementing-disposeasync

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix async dispose pattern implementation Fix DisposeAsync pattern: remove incorrect Dispose(false) call Jan 6, 2026
Copilot AI requested a review from gewarren January 6, 2026 01:31
@gewarren gewarren marked this pull request as ready for review January 6, 2026 19:24
@gewarren gewarren requested a review from a team as a code owner January 6, 2026 19:24
Copilot AI review requested due to automatic review settings January 6, 2026 19:24
@gewarren gewarren enabled auto-merge (squash) January 6, 2026 19:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects the DisposeAsync pattern documentation by removing an incorrect Dispose(false) call that was shown in both the documentation and code examples. The Dispose(bool disposing) pattern with false is intended for finalizer contexts, not for DisposeAsync() implementations. The PR also adds the missing .ConfigureAwait(false) to align with best practices.

  • Removes unnecessary and incorrect Dispose(false) call from DisposeAsync() method
  • Adds .ConfigureAwait(false) to the DisposeAsyncCore() await call in the documentation example
  • Removes the explanatory NOTE that incorrectly justified calling Dispose(false)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
docs/standard/garbage-collection/implementing-disposeasync.md Corrects the DisposeAsync() pattern example by removing the incorrect Dispose(false) call, adding .ConfigureAwait(false), and removing the misleading NOTE that explained the incorrect pattern
docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs Removes the incorrect Dispose(false) call from the DisposeAsync() method implementation to match the corrected pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement both dispose and async dispose patterns: Dispose(false) from DisposeAsync() is not necessary

2 participants