deallocating memory when using exit(1), c++
问题 I am working on a school assignment, and we were told that whenever we have an input error we should print a message and exit the program. Obviously I use exit(1), but the problem is I have memory leaks when using this functions. I don't understand why - every single variable I've used was on the stack and not on the heap. What should I do to prevent those memory leaks? Thanks! 回答1: exit does not call the destructors of any stack based objects so if those objects have allocated any memory