[erlang-questions] [Q] erlang:check_process_code/2

Bjorn Gustavsson <>
Fri Apr 18 11:15:46 CEST 2008

Ladislav Lenart <> writes:

> I tried the above for `SomeFun = fun SomeMod:f/0' and also for `fun f/0'
> (using another function from `SomeMod'). But both return false.

My answer was slightly wrong. When I said "fun", I should have said "internal fun".

fun SomeMod:f/0 is an external fun, which is implemented differently from
an internal fun (fun f/0). External funs do not refer directly to the code
for the module, but use an additional level of indirection, so it is perfectly
safe to purge a module even if external funs reference the module. Therefore,
erlang:check_process_code/2 does not consider external funs at all.

> So I either misunderstood you or my above "test case" is wrong. Could you
> please shed some light on this for me?

I can't tell, because you didn't show the code for your test case.
Maybe your code didn't actually hold the fun.

Using my own code (below), everything works as expected:

Erlang (BEAM) emulator version 5.6.2 [async-threads:0] [kernel-poll:false]

Eshell V5.6.2  (abort with ^G)
1> P = fun_proc:start().
2> P ! {'fun',some_mod:some_fun()}.
3> code:purge(some_mod).
4> code:delete(some_mod).
5> erlang:check_process_code(P, some_mod).



some_fun() ->
    fun() -> ok end.


start() ->
    spawn_link(fun hold_fun/0).

hold_fun() ->
	{'fun',Fun} ->

hold_fun(Fun) ->
	{get_fun,Pid} ->
	    Pid ! Fun
Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list