rspec/rules/S3234/csharp/rule.adoc

62 lines
1.3 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
``++GC.SuppressFinalize++`` asks the Common Language Runtime not to call the finalizer of an object. This is useful when implementing the dispose pattern where object finalization is already handled in ``++IDisposable.Dispose++``. However, it has no effect if there is no finalizer defined in the object's type, so using it in such cases is just confusing.
This rule raises an issue when ``++GC.SuppressFinalize++`` is called for objects of ``++sealed++`` types without a finalizer.
*Note:* S3971 is a stricter version of this rule. Typically it makes sense to activate only one of these 2 rules.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
sealed class MyClass
{
public void Method()
{
...
GC.SuppressFinalize(this); //Noncompliant
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
sealed class MyClass
{
public void Method()
{
...
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this useless call to "GC.SuppressFinalize".
'''
== Comments And Links
(visible only on this page)
=== is related to: S3971
=== on 7 Jul 2015, 08:43:00 Tamas Vajk wrote:
\[~ann.campbell.2] Created the first version, can you go through it? Also, I haven't set any SQALE characteristics. Which one fits best?
endif::env-github,rspecator-view[]