Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 1, 2025

The finalizers documentation was missing important guidance about the safety of accessing managed object members from finalizers. This could lead developers to write unsafe code that attempts to access managed objects that may have already been disposed.

This change adds a warning in the "Using finalizers to release resources" section that clearly advises developers against accessing managed object members from finalizers. The warning explains that managed objects might already be disposed during finalization, making them unavailable or in an invalid state, and emphasizes that finalizers should only access unmanaged resources directly.

The warning follows Microsoft documentation standards using the [!WARNING] callout format and is positioned appropriately in the section that discusses what finalizers should be used for.

Fixes #31199.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/programming-guide/classes-and-structs/finalizers.md docs/csharp/programming-guide/classes-and-structs/finalizers

Copilot AI changed the title [WIP] Cleanup of managed resources in the finalizer? Add warning about accessing managed resources in finalizers Aug 1, 2025
Copilot AI requested a review from BillWagner August 1, 2025 19:36
Copilot finished work on behalf of BillWagner August 1, 2025 19:36
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.

One small technical edit, and then this is ready

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Aug 4, 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.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review August 4, 2025 18:16
@BillWagner BillWagner requested a review from a team as a code owner August 4, 2025 18:16
@BillWagner BillWagner requested a review from tdykstra August 4, 2025 18:16
Copilot AI requested a review from BillWagner August 4, 2025 18:16
Copilot finished work on behalf of BillWagner August 4, 2025 18:16
@BillWagner BillWagner requested review from a team and adegeo August 4, 2025 18:25
@BillWagner BillWagner merged commit b648936 into main Aug 11, 2025
11 checks passed
@BillWagner BillWagner deleted the copilot/fix-31199 branch August 11, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dotnet-csharp/svc fundamentals/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleanup of managed resources in the finalizer?

3 participants