<p dir="ltr">I find the easiest way to think about (large) binaries is through remembering that they are shared "objects". Any process that has a "pointer" into a binary like that, means the binary as a whole needs to stick around. Pattern matching on binaries creates such pointers.</p>
<p dir="ltr">A common problem arises when you have one process creating such a binary,  then taking it apart using pattern matching, and passing those "parts" on for further processing. All those parts now refer back to the original large binary, which therefore cannot get collected.</p>
<p dir="ltr">In order to work around this "optimisation",  the common approach is for the process taking apart the binary to make copies of the parts to pass along for further processing. Thus references into the original binary are avoided and it can get collected. </p>
<p dir="ltr">Cheers, <br>
Robby<br>
</p>
<div class="gmail_quote">On 17 Oct 2016 13:26, "Oliver Korpilla" <<a href="mailto:Oliver.Korpilla@gmx.de">Oliver.Korpilla@gmx.de</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello.<br>
<br>
Recent reading got me concerned about leaking memory by having big refc binaries.<br>
<br>
In our system we have permanent TCP and SCTP handlers that receive outside messages, then forward it into the system for processing.<br>
<br>
For example, these events have ASN.1 payloads. Decoding is done in throw-away processes... however, I'm concerned that the TCP and SCTP handling processes might cause memory leaks because every payload buffer is handled there first.<br>
<br>
I saw in "Erlang in Anger" that routers should only return where to route to, not handle the message. But when handling sockets I don't see that option?<br>
<br>
What is good practice here? Am "I" at risk?<br>
<br>
Thanks and best regards,<br>
Oliver<br>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</blockquote></div>