Home > Code Analysis > Code Issues – Redundant Destructor

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:

CodeRush Code Issues - Redundant destructor

How to fix:

CodeRush Code Issues - Redundant destructor with a fix

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: any
Updated: Nov/12/2012
ID: C068

Similar Posts: