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

implementing-dispose.md: Better illustration of SafeHandles #45173

Merged

Conversation

antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Mar 8, 2025

Implement the plan described in #44201 (comment) and apply some further changes:

  • Use MemoryStream to demonstrate managed only dispose pattern
  • For the unmanaged dispose pattern, actually allocate a handle
  • Define a new example for working with SafeHandle in the Safe handles paragraph
  • Reshuffle the order of paragraphs so it aligns with the new content better
  • An adjustment on Clarify ownership of IDisposable objects #34144, changing the text in "Cascade dispose calls" that talks about ownership. (There is no such rule that only the members created by the class should be disposed by the class, sometimes ownership can be transferred to another IDisposable.)

Fixes #44201


Internal previews

📄 File 🔗 Preview link
docs/standard/garbage-collection/implementing-dispose.md Implement a Dispose method

@dotnetrepoman dotnetrepoman bot added this to the March 2025 milestone Mar 8, 2025
@antonfirsov antonfirsov marked this pull request as draft March 8, 2025 18:45
@antonfirsov antonfirsov marked this pull request as ready for review March 10, 2025 14:10
@BillWagner BillWagner closed this Mar 10, 2025
@BillWagner BillWagner reopened this Mar 10, 2025
@BillWagner BillWagner closed this Mar 10, 2025
@BillWagner BillWagner reopened this Mar 10, 2025
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Thanks again @antonfirsov

This looks great, and I'll :shipit: now.

Copy link
Contributor

@gewarren gewarren left a comment

Choose a reason for hiding this comment

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

I found a few more nits.

Co-authored-by: Genevieve Warren <[email protected]>
@IEvangelist IEvangelist enabled auto-merge (squash) March 11, 2025 14:28
@IEvangelist IEvangelist merged commit 920bfa3 into dotnet:main Mar 11, 2025
8 checks passed
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.

The dispose pattern docs should not use an IntPtr.Zero handle
4 participants