Consider this small program:
int main(int argc, const char *argv[])
{
int *i = new int;
//do something with i, where i is involved all the time
return 0;
}
As a matter of good style and to show that you actually know you must free memory allocated on the heap you normally add delete i; just before return statement.
But will it do any harm if leaving delete i; out?
UPDATE: Please do not flame each other in comments. I do know that just to be on safe side and just as the matter of good style and so on I should free allocated memory. The question is, can it be ommitted safely in this particular case.
There won’t be any harm. The OS deallocates all the process’s memory, when it dies.
Nevertheless not deleting your variables is a bad style as it hinders the use of tools such as Valgrind.