Empty
destructor
s will affect the application's performance35
36 // CS-P1000: Avoid empty finalizers.
37 // https://deepsource.io/directory/analyzers/csharp/issues/CS-P1000.
38 ~Perf()39 {40 }41}
Description
Finalizers, i.e., destructors, perform clean-up operations as an instance is picked up for garbage collection (GC). If a class has a finalizer defined, it is added to the Finalize
queue, which is later processed by the GC when deemed appropriate. An empty finalizer adds unnecessary additional overhead to the GC since it does not perform effective clean-up operations. Therefore, it is suggested that you either remove the empty finalizer or add relevant clean-up operations.
Bad Practice
class CSharpAnalyzer
{
// Empty finalizer
~CSharpAnalyzer()
{
}
}
Recommended
class CSharpAnalyzer
{
// Non-empty finalizer
~CSharpAnalyzer()
{
// ...
}
}