Skip to content

Commit 28c0d30

Browse files
Add DO/AVOID for SafeHandles and Finalizers(dotnet#41746)
Co-authored-by: Genevieve Warren <[email protected]>
1 parent 8e1612e commit 28c0d30

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/standard/native-interop/best-practices.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The guidance in this section applies to all interop scenarios.
2323
- ✔️ CONSIDER using <xref:System.Buffers.ArrayPool%601?displayProperty=nameWithType> to pool your native array buffers.
2424
- ✔️ CONSIDER wrapping your P/Invoke declarations in a class with the same name and capitalization as your native library.
2525
- 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.
26+
- ✔️ 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).
27+
- ❌ AVOID finalizers to manage lifetime of objects that encapsulate unmanaged resources. For more information, see [Implement a Dispose method](../garbage-collection/implementing-dispose.md).
2628

2729
## LibraryImport attribute settings
2830

0 commit comments

Comments
 (0)