0

I have a dynamic array i declare globally:

double * numbers;

I then initialize inside a function

numbers = new double[TotalNums]

I use this array from the beginning to the end of my program, do I NEED to delete it before exit, or is it just recommended to? I get no errors if i don't and i assume the OS frees up the memory after termination automatically.

Dom
  • 1,232
  • 1
  • 10
  • 20
  • 2
    If you end up with some leak detection for your program, this might come up as an annoying false positive. But no, there's no requirement to free memory for program termination, the os will take care of it. – George Feb 09 '21 at 22:20
  • 2
    Depends on what you mean by "have to". You don't "have to" deallocate memory that you allocate in similar way as you don't "have to" pay your rent. You can simply choose not to. But there will be consequences. – eerorika Feb 09 '21 at 22:20
  • What if you don't have an OS? – user4581301 Feb 09 '21 at 22:49

0 Answers0