::operator delete[] is documented on cplusplus.com (which is sometimes frowned upon) as:
operator delete[]
can be called explicitly as a regular function, but in C++, delete[]
is an operator with a very specific behavior: An expression with the delete[]
operator, first calls the appropriate destructors for each element in the array (if these are of a class type), and then calls function operator delete[]
(i.e., this function) to release the storage.
so the destructor is called n times (once for each element), and then the memory freeing "function" is called once.
Notice that each destruction might take a different time (or even complexity) than the others. Generally most destructions are quick, and have the same complexity.... But that won't be the case if each destroyed element is a complex tree or node or graph...
For primitive types like int
the fictitious destructor of int
is a no-op. The compiler probably would optimize that (if asked).
You should check the real C++11 standard, or at least its late n3337 working draft, which says (thanks to Matteo Italia for pointing that in a comment) in §5.3.5.6 page 110 of n3337:
If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will
invoke the destructor (if any) for the object or the elements of the array being deleted. In the case of an
array, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completion
of their constructor; see 12.6.2)
If you use -and trust enough- GCC 4.8 or better, you could have used the g++
compiler with the -fdump-tree-phiopt
or -fdump-tree-all
option (beware, they are dumping a lot of files!), or the MELT plugin, to query the intermediate Gimple representation of some example. Or use -S -fverbose-asm
to get the assembler code. And you also want to add optimization flags like -O1
or -O2
...
NB: IMHO, cppreference.com is also an interesting site about C++, see there about delete
(as commented by Cubbi)