There is nothing that requires a delete[]
in the standard – However, I would say it is a very good guideline to follow.
However, it is better practice to use a delete
or delete[]
with every new
or new[]
operation, even if the memory will be cleaned up by the program termination.
Many custom objects will have a destructor that does other logic than just cleaning up the memory. Using delete
guarantees the destruction in these cases.
Also, if you ever move around your routines, you are less likely to cause memory leaks in other places in your code.