1

I have understanding (probably wrong) that memory becomes free anway on application exit, so what's the point of calling delete on something that lives as long as program is running?

for example this sample code doesn't delete a pointer:

int main()
{
    int p = new int;
    return 0;
}

will memory pointed by pointer 'p' be freed to system once the program exits?

bazoni
  • 35
  • 3

1 Answers1

3

Yes, it will be deleted by the OS. It is not a good idea in case you want to use a tool like valgrind and in general is a bad code smell.

Jerome Reinländer
  • 1,227
  • 1
  • 10
  • 26
  • 1
    Yes, yes, yes. Essentially, if you make memory leaks normal in your programming, it will be very hard to eliminate memory leaks when it becomes a problem. You should never accept this in your programming or in code from your coworkers. – Nick Brown Feb 16 '18 at 14:26