I have a quick question regarding memory. After running a c++ program, is all of the memory used by the program released after the program terminates? How can I make sure that it is released?
I have a quick question regarding memory. After running a c++ program, is all of the memory used by the program released after the program terminates? How can I make sure that it is released?
Yes. Well -- this is not part of the standard, it is up to the operating system. But I think all modern operating systems do take care of that.
[edit] this is not to say you shouldn't bother with clean-up -- it's better to be in that habit than being "cleverly" lazy
Last edited by MK27; 06-09-2010 at 11:44 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
But you should not rely on this. It's considered good practice to clean up after yourself.
The easiest way is to make use of available constructs such as std::vector, std::list, etc. And if you really need to use dynamic memory, we have smart pointers as our disposal, such as std::shared_ptr (or std::tr1::shared_ptr).
Question 7.24
If you consider that your module may become part of a larger program at some point, then making sure everything is nice and tight is a good idea.
Plus it's also good practice
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.