When you use new Foo[n]
, you're making a single allocation for a chunk of memory big enough to hold an array of n
contiguous elements of type Foo
. This is not the same as allocating n
contiguous chunks of memory, one for each Foo
.
From the point of view of the memory allocator, it's really only one big allocation. When you do delete array
or delete (array + 42)
, the memory allocator is basically asked to delete the part of the big allocation that holds a specific item, which it cannot do. It's like trying to free up a single member of a new'ed object by doing delete (&(new Foo())->bar)
- what happens to the rest of the object?
Even on a single-element array, delete array
will not work because the allocator uses different bookkeeping logic for arrays and single objects (for example, storing the number of elements in the array). So you really do have to use delete[]
with new[]
and delete
with new
.