Call to
new
operator reserves some memory and it's programmers' responsibility to free this memory. Therefore each call to
new
should have a corresponding
delete
and each call to
new[]
should have a
delete[]
. But doing it properly is a difficult thing, therefore usage of
new
should be minimized. With smart pointers and containers you almost never need it (I don't think I ever used raw
new
in my 3 years of professional work). In your code you'd have to use
delete[] items;
before reassigning
items
to point to new array. —
Yksisarvinen 52 secs ago