[erlang-questions] How to upgrade running applications repeatedly

Matthias Lang <>
Fri Jun 8 10:54:58 CEST 2007

Bo writes:
 > Hello All.
 > I have tried without success to be able to update my running applications.   The code below is a very simple example in which there is a loop, that will always call itself with ?MODULE:loop(L) which according to the documentation should always call the latest version of itself, but this is what happens:
 > 1) I start the app with test1:start().
 > 2) I compile it and send some message to it, everything works
 > 3) I repeat step 2 and the program fails

Ok, so the problem turned out to be that old code was still running on
the second code load (which happened implicitly as part of the

Some suggestions:

  - Take a look at code:soft_purge/1 

  - By default, use spawn_link() or proc_lib:spawn_link() and not
    plain spawn. Most of the time, you don't want processes to die
    silently. (Ulf Wiger already suggested this)

  - Don't be "too clever" with funs. There are a few gotchas which
    affect code loading. You can read a bit more here, under "Do 
    funs behave during a code change?"


Experimenting with the basics, e.g. writing a 'server' process from
scratch, is a great way to learn. And then you can forgive gen_server
for not being so pretty, because it gets the fiddly details right so
that you have to go out of your way to screw up code loading.


More information about the erlang-questions mailing list