Purpose of Placement delete

Purpose of Placement delete

C++ defines a placement version of operator delete. Placement delete is not supposed to be called directly by the user. Rather, it merely serves as the deacllocation function that the implementation must invoke when an exception occurs during the construction of an object by placement new. To generalize, for every version of operator new, C++ provides a matching operator delete. Since there are six versions of operator new (ordinary new, placement new, nothrow new, as well as their array counterparts), there are also six corresponding versions of delete.

As opposed to a common belief, placement delete does not invoke the destructor of its argument; in fact, it has no effect. To ensure that an object constructed by placement new is destructed, you need to call its destructor explicitly.


Share the Post: