[erlang-questions] question: "Erlang literals are no longer copied when sending messages."

Boshan Sun sunboshan@REDACTED
Thu Oct 26 18:03:30 CEST 2017


Does those literals lives in the constant heap has a ref counter, as the
refc binary? If not, how do they get garbage collected? If so, will those
constant suffers same "memory leak" issue has refc binary?(a process
touched lots of refc binary but never get garbaged collected, so those refc
binaries cannot be garbage collected for a long time)

Thanks!

2017-10-26 7:39 GMT-07:00 Jesper Louis Andersen <
jesper.louis.andersen@REDACTED>:

> The compiler detects literal constants. A function such as
>
> f() -> ["I", "am", "a", "literal", "constant", "valiue"].
>
> will return a constant list. These lists go into a "constant heap" which
> means that other heaps can just reference those values directly from there.
> Prior to Erlang version 20.0, if you sent such a constant (locally) from
> one process to another, the send would copy the constant literal into the
> mailbox of the receiving process. Not anymore. The value is referenced from
> the constant heap. There is a subtlety when you load new code in which the
> old constants are correctly retained by the VM, but otherwise, things works
> seamlessly for programmers.
>
> Your example is somewhat degenerate because the empty list and empty map
> already has special representation in the VM. One way to detect if a value
> is a constant is to look at the output from the compiler. The module will
> have a special section for constant literals, and you can verify that the
> compiler indeed did detect a value as being a constant. In general,
> constants are congruences in the sense that compounding structures are
> constants if all their children are in the term tree.
>
>
> On Thu, Oct 26, 2017 at 1:18 PM Benoit Chesneau <bchesneau@REDACTED>
> wrote:
>
>> With Erlang 20, "Erlang literals are no longer copied when sending
>> messages" according to the changelog.
>> Does it means something like #{ somelist => [], map => #{ } } will be
>> returned from a gen_server call without beeing copied?  (ie the content of
>> somelist and somemap will only be referenced ?
>>
>> Benoit
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171026/d109f29b/attachment.htm>


More information about the erlang-questions mailing list