dotnet / dotnet/dotnet-api-docs
IDisposable.Dispose Method – SafeHandle is used to release unmanged resource not otherwise
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
From [Remarks](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable.dispose?view=net-5.0#remarks)
> Because the Dispose method must be called explicitly, there is always a danger that the unmanaged resources will not be released, because the consumer of an object fails to call its Dispose method. There are two ways to avoid this:
• Wrap the managed resource in an object derived from System.Runtime.InteropServices.SafeHandle…
From [The SafeHandle alternative](https://docs.microsoft.com/en-us/dotnet/api/system.object.finalize?view=net-5.0#the-safehandle-alternative)
> Instead of implementing a finalizer for your class to release unmanaged resources, you can use an object that is derived from the System.Runtime.InteropServices.SafeHandle class to wrap your unmanaged resources, and then implement the dispose pattern without a finalizer.
Contributor guide
Assessment
This issue has not been assessed yet.