[erlang-questions] Understanding binary heap garbage collection

Ward Bekker (TTY) <>
Fri Nov 23 10:42:17 CET 2012


Yes, this is the solution. Thx!

On 23 nov. 2012, at 10:10, Slava Yurin <> wrote:

> Hi, Ward. 
>  
> Because erlang shell save history for you. Garbage collect not affect to constructed binary.
>  
> try:
> spawn(fun() -> lists:foldl(fun(_I, Acc) -> <<Acc/binary, Acc/binary>> end, <<"abc">>, lists:seq(0,21)) end).
>  
> And you will see that no such big increase in binary heap.
>  
> 23.11.2012, 15:57, "Ward Bekker (TTY)" <>:
>> Hi,
>> After an operation with binaries, and manual requesting a garbage collect, the binary heap does not shrink to it's former size. See my test sequence below. About 1.5 MB is added to the binary heap, and never garbage collected. What can be the cause?
>> /W
>> =========
>> Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]
>> 
>> Eshell V5.9.2  (abort with ^G)
>> 1> erlang:memory().
>> [{total,9654968},
>>  {processes,1123090},
>>  {processes_used,1123090},
>>  {system,8531878},
>>  {atom,194289},
>>  {atom_used,176885},
>>  {binary,1319320},
>>  {code,3892513},
>>  {ets,298400}]
>> 
>> 2> lists:foldl(fun(_I, Acc) -> <<Acc/binary, Acc/binary>> end, <<"abc">>, lists:seq(0,21)).
>> <<"abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"…>>
>> 
>> 3> erlang:memory().
>> [{total,22340920},
>>  {processes,1127984},
>>  {processes_used,1127970},
>>  {system,21212936},
>>  {atom,202481},
>>  {atom_used,186083},
>>  {binary,13901920},
>>  {code,3972848},
>>  {ets,302504}]
>> 
>> 4> erlang:garbage_collect().
>> true
>> 
>> 5> erlang:memory().
>> [{total,22314232},
>>  {processes,1100552},
>>  {processes_used,1100538},
>>  {system,21213680},
>>  {atom,202481},
>>  {atom_used,186083},
>>  {binary,13902664},
>>  {code,3972848},
>>  {ets,302504}]
>> 6> 
>> ,
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121123/72a51a42/attachment.html>


More information about the erlang-questions mailing list