Reputation: 8713
Does delete ptr
differ from operator delete(ptr)
only in this, that delete
calls ptr
destructor? Or in other words, does delete ptr
first call a destructor of ptr
and then operator delete(ptr)
to free allocated memory? Then is delete ptr
technically equivalent to the following:
T * ptr = new T;
//delete ptr equivalent:
ptr->~T();
::operator delete(static_cast<void *>(ptr));
?
Upvotes: 14
Views: 2274
Reputation: 88155
delete ptr
will do overload resolution for operator delete
, so it may not call the global ::operator delete
But otherwise, yes. The delete
operator calls the relevant destructor, if any, and then calls operator delete
.
Upvotes: 9