Working with large binaries in the interpreter

Bob Ippolito <>
Fri Sep 1 21:39:54 CEST 2006

I'm writing an application that has a large (database) file that it
keeps as a binary in memory (24.54M). Normally I would use something
like mmap for this purpose, but I haven't found a similar facility in

The problem is whenever I get a traceback with that binary on the
stack or otherwise end up with a printed representation of the binary
at the interpreter, memory usage grows enormously and it doesn't go
down. If this happens more than once, I start swapping. Is there
anything I can do about this? It's really difficult to debug when I
have to kill beam at any error.

Also, the binary size seems suspiciously high. There should be exactly
one 25737850 byte (24.54M) binary, but there's 16271355 bytes (15.5M)
unaccounted for. It should not be a view on a larger binary, because
that binary is the entire file uncompressed.

(This is Erlang/OTP R11B-0 on Mac OS X 10.4 intel)

Erlang (BEAM) emulator version 5.5 [source] [async-threads:0]

Eshell V5.5  (abort with ^G)
1> erlang:memory().
2> {ok, D} = egeoip:new(), garbage_collect().
3> erlang:memory().
4> 42071665 - 62460 - size(element(5, D)).
5> D. garbage_collect().
6> garbage_collect().
7> erlang:memory().

Why did processes grow by 445046636 bytes (424.43M) after printing
that representation?!


More information about the erlang-questions mailing list