C#

C#

Made by DeepSource

Avoid empty finalizers CS-P1000

Performance
Critical
Autofix

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()
    {
        // ...
    }
}

Reference