[erlang-questions] Garbage Collection, BEAM memory and Erlang memory

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Fri Jan 23 14:58:05 CET 2015


On Fri, Jan 23, 2015 at 1:26 PM, Roberto Ostinelli <roberto@REDACTED>
wrote:

> I do not have such system yet in place, as this isn't a production
> environment (yet).
>
> Will definitely add one asap.
>

In my experience, instrumentation of the running production/development
system is one of the most important things to add early on. The views of
the system it gives and the depth at which it explains what is going on
will help in so many debugging scenarios you can't fathom it.

My hunch is you are holding on to binary values for too long in some
processes, or are storing a ref-c binary in ETS which keeps the underlying
binary alive. The two major ways to handle this has already been mentioned.

If you are picking apart a large binary, and you need to reference *binary*
data in it, then it may be beneficial to break that binary data off:

<<Payload:Len/binary, "\r\n", Rest/binary>> = Packet,
CPayload = binary:copy(Payload),
...
recurse_on(Rest).

but as Dan says, copying `Rest` in this case is a bad idea. You just copy
the very binary you are running over and processing. Also note that it is
important you are picking out binary data. If you had something like

<<I:32/integer, "\r\n", Rest/binary>>

then the integer conversion already excises the data from the binary, so
you don't have to keep the binary around anymore.


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150123/08cf8e1c/attachment.htm>


More information about the erlang-questions mailing list