# C++: have to 'delete[]' after using 'new T[0]'?

This topic is 3104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Should be a simple question, but I haven't been able to find the answer. If you do
int* x = new int[0];
, 'x' is not NULL. Do you still need to 'delete[]' it, even though no useable memory was allocated?

Yes.

##### Share on other sites
Been a long time since I used C++ so I really don't remember but my general rule of thumb is if I can't find something explicitly stating what should happen then it is by definition undefined behavior. In that case you just shouldn't do it.

 SiCrane with the ninja.
It states here that the only legal and in fact <required> operation is to delete[] it.
http://stackoverflow.com/questions/1087042/c-new-int0-will-it-allocate-memory

##### Share on other sites
WHENEVER you use new like this :

dataType heap = new dataType; (i.e no brackets)

you accompany it by using delete heap;

and WHENEVER you use brackets with new like this :

dataType heap2 = new dataType[someNumber]; (i.e new with brackets)

you need to accompany new with delete [] heap2 after your done.