I see the following constructs:
new X
will free the memory if X
constructor throws.
operator new()
can be
When the construction of the object being constructed as a part of the new-expression fails, a corresponding deallocation function -- if there is one -- will be called. For instance
new X;
will use the following pair of allocation/deallocation functions.
void * operator new(std::size_t);
void operator delete(void *);
Similarly, for a placement new of the form
new(&a) X;
the placement versions of operator new
and operator delete
function will be used.
void * operator new(std::size_t, void *);
void operator delete(void *, void *);
Note that the last function intentionally performs no action.