Require GC.SuppressFinalize(this) when virtual dispose?
See original GitHub issuepublic abstract class C : IDisposable
{
public void Dispose()
{
this.Dispose(true);
// Require GC.SuppressFinalize(this); here?
}
protected virtual void Dispose(bool disposing)
{
...
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
When should I use GC.SuppressFinalize()?
In general, most any Dispose() method should be able to call GC.SupressFinalize() , because it should clean up everything that would be cleaned ......
Read more >CA1816: Call GC.SuppressFinalize correctly (code analysis)
Dispose method is called, it frees resources of the object. This makes finalization unnecessary. IDisposable.Dispose should call GC.
Read more >Be Careful Where You Put GC.SuppressFinalize - Alois Kraus
You should always call GC.SuppressFinalize from Dispose if you have a finalizer, not just when there is “a reason to finalize”, e.g. this.handle ......
Read more >Dispose() methods should call GC.SuppressFinalize
List all Dispose() methods that do not call GC.SuppressFinalize(). This applies only for Dispose() method defined in classes which implement the ...
Read more >CA1816: Call GC.SuppressFinalize correctly -- Redundant ...
Dispose () is not virtual. It is not possible for a derived type to correctly add the call to GC.SuppressFinalize , and it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In the current
Dispose
pattern, the call toSuppressFinalize
is required if you have a virtualDispose
method and the containing type (C
in this case). It does not matter whether a user-defined finalizer is present.The rule is not optional in this pattern so you do not need a configuration option to disable it. New guidance for
IDisposable
which removes this requirement as part of a broad simplification is in progress but not yet approved as a recommendation.We keep it as default warning for now then.