Описание тега delete-operator

In the C++ programming language, the delete operator calls the destructor of the given argument, and returns memory allocated by new back to the heap.

A call to delete must be made for every call to new to avoid a memory leak. After calling delete the memory object pointed to is invalid and should no longer be used. Many programmers assign 0 (null pointer) to pointers after using delete to help minimize programming errors.

Note, however, that deleting a null pointer has no effect (if the deallocation function is one supplied in the standard library), so it is not necessary to check for a null pointer before calling delete.

Arrays, allocated with new[], must be deallocated with delete[].