| Re: Is delete dangerous, when delete[] is appropriate? |
|
 |
|
 |
|
 |
|
 |
Group: comp.lang.c++.moderated · Group Profile
Author: peter koch larsenpeter koch larsen Date: Jul 10, 2007 08:39
On 10 Jul., 14:28, ted trhj.homeunix.net> wrote:
> If I use delete, when delete[] is correct, can the consequence be
> anything
> worse than a memory leak?
Yes. What happens is not specified, but typical behaviour includes
memory leaks, missing destructor calls, heap corruption and crash.
>
> E.g.
> int* pi = new int[2];
> delete pi; // delete[] is correct
>
There's practically never any reason to use new[]. Prefer using
std::vector which has very low overhead and offers additional safety
and lots of extra goodies such as resizing.
/Peter
|