Garbage collection. Bug or feature?

Fyodor Ustinov ufm@REDACTED
Tue Sep 1 14:29:07 CEST 2009


Hi!

I thought that in the case of dynamic garbage collection, memory
allocation is roughly as follows:

for(int i = 0, mem=alloc(size); mem == NULL && i < MaxAttempts;
garbage_colelct), i++;

while MaxAttempts should be at least 1.

But the following examples indicate the contrary.

ufm@REDACTED:~$ erl
Erlang R13B01 (erts-5.7.2) [source] [smp:2:2] [rq:2] [async-threads:0]
[kernel-poll:false]

Eshell V5.7.2  (abort with ^G)
1> A=[255||X<-lists:seq(1,20000000)],ok.
ok
2> B=list_to_binary(A).
<<"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"...>>
3> byte_size(B).
20000000
4> byte_size(B).
20000000
5> byte_size(B).
20000000

Crash dump was written to: erl_crash.dump
eheap_alloc: Cannot allocate 912262800 bytes of memory (of type "heap").
Aborted

ufm@REDACTED:~$ erl
Erlang R13B01 (erts-5.7.2) [source] [smp:2:2] [rq:2] [async-threads:0]
[kernel-poll:false]

Eshell V5.7.2  (abort with ^G)
1> A=[255||X<-lists:seq(1,20000000)],ok.
ok
2> B=list_to_binary(A).
<<"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"...>>
3> erlang:garbage_collect(),byte_size(B).
20000000
4> erlang:garbage_collect(),byte_size(B).
20000000
5> erlang:garbage_collect(),byte_size(B).
20000000
6> erlang:garbage_collect(),byte_size(B).
20000000
7> erlang:garbage_collect(),byte_size(B).
20000000
8> erlang:garbage_collect(),byte_size(B).
20000000
9> [...and so on...]

Calling the garbage collector manually - not a good idea. But in real
life I do not know the size of B, it can be anything, therefore,
compelled to do so.


So all the same, this is a bug, feature or I misunderstood something?




More information about the erlang-bugs mailing list