如果我在 C++ 中调用 new,但堆内存不足,会发生什么情况?

what happens if I call new in c++, but the heap is out of memory?

我很好奇当堆内存已满并且我们在c++中调用new运算符或在c中调用malloc时会发生什么?有没有办法清除整个堆内存?

来自"New and delete (C++)" on Wikipedia

If not enough memory is available in the free store for an object of type T, the new request indicates failure by throwing an exception of type std::bad_alloc. This removes the need to explicitly check the result of an allocation.