[erlang-questions] Memory Usage
Wed Sep 30 15:49:10 CEST 2009
On Tue, Sep 29, 2009 at 6:11 PM, Erickson, John <john.erickson@REDACTED> wrote:
> Hi, I am trying to store a large list of items and am a little surprised how much memory erlang is using. As a test, I tried creating a list of 10M integers and measuring memory usage. It takes around 600M. If I convert this list to a binary using term_to_binary, it is only about 50M, which is more like what I would expect. So I am wondering why there is 10x memory usage in the usual form? One other small oddity, it seems after calling garbage_collect I am using more memory.
It is not meaningful to use memory/0 to draw any conclusions about
memory usage for an expression you have evaluated in the shell. The reason
is that the shell internally uses multiple processes that communicate with each
other, and those processes can be garbaged-collected at different times.
To find out how many heap words a data structure requires, use one of
erts_debug:flat_size(Term) or erts_debug:size(Term) functions. (Unless
the Term contains
shared sub terms, they return the same result, but
erts_debug:flat_size/1 is faster.) If you run
the 32-bit emulator, multiply the value with 4 to obtain the memory
consumption in bytes (otherwise,
multiply with 8 for the 64-bit emulator).
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions