JetBrains Rider 2024.1 Help

Code inspection: Empty destructor

An empty destructor does not contain any special actions that must be completed before the object is reclaimed by the garbage collector. Such a destructor adds nothing to what the garbage collector will do automatically, it only causes overhead.

In C#, destructors are used instead of overrides of the Finalize method to provide finalizers for your classes. If a class has a destructor, the garbage collector marks the corresponding objects for finalization: for each object it adds an entry to the so called finalization queue. At destructor invocation, the garbage collector is invoked — it analyzes the finalization queue and runs a finalizer. If a destructor is empty, the finalizer does not contain any user-defined instructions, so all operations with the finalization queue and finalizers are unnecessary and only consume resources.

JetBrains Rider suggests removing an empty destructor to improve both readability and performance of your code.

Last modified: 11 February 2024