[erlang-questions] investigating memory issues

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Sat Oct 17 12:50:51 CEST 2015


On Fri, Oct 16, 2015 at 9:34 PM, Caragea Silviu <silviu.cpp@REDACTED>
wrote:

> 7. jsonx


This is a shot but I think this library is your problem. When it parses a
JSON document, it uses enif_make_sub_binary on the binary() containing the
JSON string. This means if you do not use binary:copy() on data you hoist
out of the JSON document, then you are keeping the whole document around
for as long as you refer to that subbinary.

Try wrapping strings you hoist out in binary:copy/1. This will slow you
down, but it should remove the reference to the original binary which would
make your system be able to reclaim that memory. Alternatively, if your
system is not highly loaded, you could simply replace jsonx for jsx which
is written in Erlang and avoids such problems (at the expense of slower
parsing, but JSON will *never* win a parsing race anyway and it is better
to swtch the format then).

I've seen systems stuffing such subbinaries into ETS, and then your ETS
table is keeping data around.


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


More information about the erlang-questions mailing list