Skip to content

Commit

Permalink
Add DO/AVOID for SafeHandles and Finalizers(#41746)
Browse files Browse the repository at this point in the history
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
  • Loading branch information
AaronRobinsonMSFT and gewarren committed Jul 14, 2024
1 parent 8e1612e commit 28c0d30
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/standard/native-interop/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The guidance in this section applies to all interop scenarios.
- ✔️ CONSIDER using <xref:System.Buffers.ArrayPool%601?displayProperty=nameWithType> to pool your native array buffers.
- ✔️ CONSIDER wrapping your P/Invoke declarations in a class with the same name and capitalization as your native library.
- This allows your `[LibraryImport]` or `[DllImport]` attributes to use the C# `nameof` language feature to pass in the name of the native library and ensure that you didn't misspell the name of the native library.
- ✔️ DO use `SafeHandle` handles to manage lifetime of objects that encapsulate unmanaged resources. For more information, see [Cleaning up unmanaged resources](../garbage-collection/unmanaged.md).
- ❌ AVOID finalizers to manage lifetime of objects that encapsulate unmanaged resources. For more information, see [Implement a Dispose method](../garbage-collection/implementing-dispose.md).

## LibraryImport attribute settings

Expand Down

0 comments on commit 28c0d30

Please sign in to comment.