It is said that atoms are not garbage collected. Once you’ve created an atom, it remains in the atom table, which might cause memory leakage at the end of the day!
I
While I'm not sure atoms are garbage-collected, you can easily do without worrying whether you will blow up the system's memory. As @Chiron said, as long as all your atoms are known at compile time you should be ok.
What if I really need to use list_to_atom/1
somehow? Well, you may be able to twist your issue using this kind of function:
atom("apple") -> apple;
atom("orange") -> orange;
atom("banana") -> banana.
One other workaround is list_to_existing_atom/1
But the VM can still eat more and more RAM: other connected Erlang nodes may register atoms globally, that is allocate atoms at run time.