[erlang-questions] why call code:purge(Module) twice?

Richard Andrews <>
Wed Mar 11 05:55:43 CET 2009






----- Original Message ----
> reload() ->
>     reload([mod1,mod2,mod3]).
> reload(Module) when is_atom(Module) ->
>     code:purge(Module),
>     code:delete(Module),
>     code:load_file(Module),
>     true;
> reload([]) -> ok;
> reload([?MODULE | T]) -> reload(T);
> reload([H|T]) ->
>     reload(H),
>     reload(H),
>     reload(T).
> 
> It reloads the list of modules that make up my server. What I don't
> understand is why it calls reload(Module) twice.
> If I understand the Erlang documentation correctly calling code:purge()
> twice will kill all running erlang processes, making it pretty much a
> cold code start.
> What would be a reason to do this? I can imagine that sometimes old
> processes wouldn't be able to cope with processes running new code, in
> which a clean start would be needed. But in that case a graceful stop
> and start would be nicer.

It's not so much about purging twice, but loading twice.

My understanding is that purge+load will load in the new code and any old version will go to the "old" space. Doing another purge+load will cause the originally running code to be dropped by the VM entirely ("old" is now the result of the first code:load_file) and so any processes using the original code will be forced to exit instead of continuing with "old" code.

--
  Rich


      Stay connected to the people that matter most with a smarter inbox. Take a look http://au.docs.yahoo.com/mail/smarterinbox



More information about the erlang-questions mailing list