There is a common myth among C++ programmers that it is okay to use
to release dynamically allocated arrays (via
) for built-in types. For example
int *p=new int;
This is totally wrong. The C++ standard specifically says that using
to release dynamically allocated arrays of any type yields undefined behavior. The fact that, on some platforms, applications that use
do not crash; can be attributed to sheer luck.
, for instance, implements both
for built-in types by calling
function. However, there is no guarantee that future releases of Visual C++ will adhere to this convention. Furthermore, there is no guarantee that this code will work on other compilers.
To conclude, using
delete instead of
delete and vice versa is hazardous and should be avoided.