[erlang-questions] Dynamically generated atoms get reused if they are the same?

Kenneth Lundin kenneth.lundin@REDACTED
Mon Nov 5 23:37:05 CET 2007


It is only an increasing number of different atoms which can cause the
VM to allocate more and more memory and sooner or later run out of

So if you use list_to_atom on a limited set of values you are safe.
There is also the function list_to_existing_atom which let you convert
a string to an atom only if the atom already exist.

If for example the atoms are used as literals in the code in some module and
this module is loaded then the atoms already exist when list_to_atom
creating some
of the atoms used in the module is called.

/Kenneth Erlang/OTP team at Ericsson

On 11/5/07, nindeu@REDACTED <nindeu@REDACTED> wrote:
> Hi,
> According to http://www.erlang.org/doc/efficiency_guide/bif.html#6.1 atoms do not get garbage collected. Meaning if you constantly produce atoms by using list_to_atom/1 you sooner or later will run out of space for them.
> Now I just wrote a small test program which indicates that as long as you produce the same atom, it will not take up additional space:
> atomTest() ->
>  NewAtom = list_to_atom("itsme"),
>  io:format("New memory size: ~p, Atoms used: ~p~n",
>    [erlang:memory(atom), erlang:memory(atom_used)]),
>        register(NewAtom, self()),
>        unregister(NewAtom),
>        receive
>        after 1000 ->
>                atomTest()
>  end.
> So, can anyone confirm, is it correct that dynamically generated Atoms are of no concern as long as you do not produce too many _different_ ones?
> Thank you!
> Regards,
> Eric
> --
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list