In general, even if your code is compiled with -fno-exceptions (then new will not throw std::bad_alloc , but it will return nullptr ), the standard C ++ libstdC ++ library is compiled with exceptions, then new will still throw std::bad_alloc when you run out of memory.
However, seriously, when you are running out of memory, you can do it best as quickly as possible (most often). If you need some kind of reliability, itβs much easier to have a monitoring process that will restart your application.
What does the V8 do? Obviously, they overloaded the new operator, and when the distribution fails ( malloc() still returns NULL , of course), they call a special function to handle low-memory conditions. It discards some debugging information, reports this error (you may have your own error handler), and then (if the error handler returns) calls FATAL() to exit the application.
Check out the source code for api.cc on GitHub . From the code, simply:
When V8 cannot allocate allocated memory, FatalProcessOutOfMemory is called. The default OOM error handler is called and execution stops.
Adriano repetti
source share