0

recently, I've just learned that there are some cases where the program C++ does not end/exit at the "main" function "return" keyword. From my understanding, this raises the task to do manual clean up of objects and data in the program... of course to have a proper clean up

therefore, in case I have to write a destructor/cleaning up function for a program to replace for the default cleaning up, what should be considered? e.g. all object's destructors? dynamic memory variables? ... any else?

TSL_
  • 2,049
  • 3
  • 34
  • 55
  • actually, from some reading, I mostly understand that a clean up including calling destructor of all currently used objects and cleaning up of dynamically allocated data/objects using delete. Am I understanding right? – TSL_ Feb 03 '15 at 03:58
  • Are you asking if you quit the app does your memory get cleaned up? Say for example using `exit(int)`? – BlamKiwi Feb 03 '15 at 04:04
  • Check this answer about stack unwinding and RAII: http://stackoverflow.com/a/2331413/92957 – Eugene Feb 03 '15 at 07:42
  • @Dragon: this is one comment of someone in SO "Using exit is not nice. It breaks all those RAII objects that we have spent time building correctly. It is a lot nicer to throw back to main. If on the other hand the program is corrupted you should really call std::terminate()" – TSL_ Feb 03 '15 at 07:43
  • even so, they continued to reject all methods of exiting the program, since functions like exit, terminate, abort don't do the clean up http://stackoverflow.com/questions/4038302/how-do-i-make-a-c-console-program-exit – TSL_ Feb 03 '15 at 07:44

0 Answers0