devxlogo

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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist