[erlang-questions] automatic garbage collection when low memo ry?

Bjorn Gustavsson bjorn@REDACTED
Thu Mar 27 08:09:05 CET 2008

Convey Christian J NPRI <ConveyCJ@REDACTED> writes:

> But more generally, why should Erlang crash when it gets low on memory?
> Does the Erlang runtime not check for a malloc() or 'new' call returning NULL?  If so, that seems kind of crazy.
> Or if the Erlang runtime *does* know when a memory allocation fails, wouldn't it make more sense for it to force garbage collection to occur and try again, rather than simply crashing?

Erlang does check for a failed memory allocation, and terminates in a controlled way
(with a crash dump).

We deliberately don't try to handle memory allocation failures, becase in general
that would only delay termination of the Erlang system. For instance, if the Erlang
emulator would terminate the offending process, that could cause the Erlang system
to terminate anyway if the process was a vital system process or a process that is
supervised. There is also the problem that one process may allocated huge amounts
of memory, but the actual failing call is from another process with tiny amounts of
memory, in which case the wrong process would be killed.

In the kind of systems that Erlang is normally used in, if one Erlang node has fatal 
problems, you want it to terminate as soon as possible so that another node can take
over and the failed node to be restarted as fast as possible.

Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list