You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rules CA1816 and CA1063 are annoying me for a small detail for over 10 years: why is the CA1816 and CA1063 still forcing a call to the CG.SuppressFinalize method when the class do NOT have any finalizer?
As stated in the IDispose snippet in VS, by Stephen Cleary in his blog here: https://blog.stephencleary.com/2009/08/second-rule-of-implementing-idisposable.html
a class implementing IDisposable with only managed objects should NOT have any finalizer, and do NOT need a call to CG.SuppressFinalize
If obj does not have a finalizer or the GC has already signaled the finalizer thread to run the finalizer, the call to the SuppressFinalize method has no effect.
but this is just useless: every .NET developer dealing mostly with managed code is adding a line of code for nothing in his code.
IMHO, it would be much better to detect if the class has a finalizer, and if no finalizer, do not ask for SuppressFinalize !
Even better would be to detect for unmanaged ressources and only then ask for a finalizer and possibly SuppressFinalize as in the 3rd rule of implementing IDisposable: https://blog.stephencleary.com/2009/08/third-rule-of-implementing-idisposable.html
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 3fd3e94e-7b6f-21ad-4c90-460e60482ab5
Version Independent ID: 15958b42-33bb-4925-2d78-eb72113ba3eb
The rules CA1816 and CA1063 are annoying me for a small detail for over 10 years: why is the CA1816 and CA1063 still forcing a call to the CG.SuppressFinalize method when the class do NOT have any finalizer?
As stated in the IDispose snippet in VS, by Stephen Cleary in his blog here:
https://blog.stephencleary.com/2009/08/second-rule-of-implementing-idisposable.html
a class implementing IDisposable with only managed objects should NOT have any finalizer, and do NOT need a call to CG.SuppressFinalize
Adding CG.SuppressFinalize will not harm since
https://docs.microsoft.com/en-us/dotnet/api/system.gc.suppressfinalize?redirectedfrom=MSDN&view=net-5.0#System_GC_SuppressFinalize_System_Object_
but this is just useless: every .NET developer dealing mostly with managed code is adding a line of code for nothing in his code.
IMHO, it would be much better to detect if the class has a finalizer, and if no finalizer, do not ask for SuppressFinalize !
Even better would be to detect for unmanaged ressources and only then ask for a finalizer and possibly SuppressFinalize as in the 3rd rule of implementing IDisposable:
https://blog.stephencleary.com/2009/08/third-rule-of-implementing-idisposable.html
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: