[erlang-questions] garbage collection: when?

Roberto Ostinelli roberto@REDACTED
Wed Jun 1 13:04:17 CEST 2011


Dear list,

afaik garbage collection in erlang is per process, but if a process gets
large, it is automatically switched over to a generational scheme. What is
unclear to me is when the collection happens. Let me illustrate with a very
simple example.


start() ->
    Var = [{one, 1}, {two, 2}, ...,{thousand, 1000}],
    loop(Var).

loop(Var) ->
    ...
    other_stuff(Var).

other_stuff(Var) ->
    ...
    NewVar = lists:keyreplace(one, 1, Var, {one, "one"}),
    do_some_other_stuff(NewVar).

do_some_other_stuff(Var) ->
    ...,
    loop(Var).


My question is: when will the original list be garbage collected? Only when
this whole process exits? When we go back to loop/1? What if Var was quite
big [or you had many of these processes] and you wanted to optimized memory
management?

Any input welcome..

r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110601/f7cc8c87/attachment.htm>


More information about the erlang-questions mailing list