Code Issues – Redundant Destructor
February 10th, 2011
Cause:
Destructors are invoked automatically, and used to destroy instances of classes. The developer has no control over when the destructor is called, because this is determined by the garbage collector. Redundant destructor is a an empty destructor without any code inside, that can be safely removed.
Empty destructors should not be used at all. If a class contains a destructor, an entry is created in the “Finalize queue”, controlled by the garbage collector. When the destructor is called, the garbage collector is invoked to process the queue. If the destructor is empty, this just causes a needless loss of performance.
Sample:
How to fix:
- Apply the Remove Redundant Destructor refactoring: