Do I always need a deconstructor?

0 David V · October 20, 2015
In what cases Do I need to use a deconstructor?

thanks for the help.

Post a Reply


Oldest  Newest  Rating
0 David V · October 21, 2015
So I should only be interested to use a deconstructor when I use a function that uses pointers or strings for example, Am I right? In that cases if I don't use deconstructor I would be saving memory that I am not going to use.
0 Dol Lod · October 22, 2015
Basically, are you using dynamic memory in your class or as Krootushas said about running code when your object is destroyed? If you are, that dynamic memory needs to be cleaned up. If you fail to release that memory, you create what is called a memory leak. This leads to poor performance and can cause bugs in your program.

Classic example would be a linked list. If I add several nodes to it, when the destructor is called, the memory used by those nodes will not be released creating a memory leak.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator