This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: operator new[] and operator delete[]
- From: "Young, Michael" <Michael dot Young at paetec dot com>
- To: "Wesley Smith" <wesley dot hoke at gmail dot com>, "MSX to GCC" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 30 Jul 2007 17:34:50 -0400
- Subject: RE: operator new[] and operator delete[]
> I've noticed if I do:
>
> Object *o = new Object[100];
>
> It calls new[] but if I do
>
> delete o;
>
> later it calls delete and therefore isn't symmetrical. How can I get
> delete[] called?
You need to call the array delete using the following syntax :
delete [] o;
If you simply "delete o;", as in your example, you are only deleting the
first object in the array (and leaving 99 "orphaned" objects in memory).
- Mike