Wednesday, October 18, 2006

Puzzle resolved
Just in case anyone's wondering what the solution to last Fridays puzzle was: the bug is that the interface is missing a virtual destructor!
The compiler generates a default non-virtual destructor. That means when delete is called on a pointer who's type is BuggyInterface* only that class's destructor is called, not that of the derived class.
Any heap memory possibly allocated in the derived class that the destructor might free will remain allocated - i.e. a memory leak!

0 Comments:

Post a Comment

<< Home