To understand what this change is, you need to understand why there is a problem with placement new in the first place. Consider the following code:

	Thing* factory(bool persistent)
	{
		Thing* p = new (persistent) Thing;
		return p;
	}

What happens if Thing::Thing() throws an exception? If the operator new that is called allocated memory, what will happen to that memory?

With the standard placement new, i.e., the one provided by the library, no allocation takes place so there is no problem. If you provide a custom operator new you probably are allocating memory and, quite likely, you are doing so in a way that the standard operator delete is not appropriate to deallocate it. What you need to be able to do is declare a version of operator delete that "matches" your operator new.


Placement delete provides exactly that facility. In the example above, Thing probably has a member:

	void* operator new(size_t, bool);

which allocates memory in the appropriate place. If the Thing constructor throws an exception, the compiler will now arrange for a matching operator delete to be called if one exists. "Matching" means a declaration in the same scope as the operator new with the same parameter list except that size_t is replaced by void* so Thing should also have a member:

	void operator delete(void*, bool);

This will be called only when a constructor in a placement new throws an exception and it will be passed exactly the same arguments as were passed to operator new:

	void Thing::operator delete(void* p, bool persist)
	{
		if (persist)
			// release persistent memory allocated
			// by Thing::operator new
		else
			// release heap memory allocated by
			// Thing::operator new
	}

There is no syntax for a placement delete expression but you can always call the destructor and then explicitly call the placement operator delete function.


See also The Casting Vote: Austin - March '95.