How does C++ free the memory when a constructor throws an exception and a custom new is used
- 阅读更多 关于 How does C++ free the memory when a constructor throws an exception and a custom new is used
问题 I see the following constructs: new X will free the memory if X constructor throws. operator new() can be overloaded. The canonical definition of an operator new overload is void *operator new(size_t c, heap h) and the corresponding operator delete . The most common operator new overload is placement new, which is void *operator new(void *p) { return p; } You almost always cannot call delete on the pointer given to placement new . This leads to a single question: How is memory cleaned up when