I went back to building on ruby during an interview and I was asked to explain symbols. It got me thinking about ruby symbols and elixir atoms. One of the big differences between ruby symbols and elixir atoms is that atoms aren’t garbage collected and thus there is a possibility of atom exhaustion.
So my question is still why aren’t atoms GC’d. My first thought is because module names and some keywords like false, true and nil are internally represented as atoms it is better to have them in memory the whole time. But that doesn’t seem correct to me.
And is there a way to manually free an atom once it has been declared and you are sure it is no longer being used?
Ah my mistake, erlang atoms. It is an intersting read. I see that the discussion is pretty old. Interesting to see that even the Prolog community had to make a choice about GC:ing atoms.
Well, technically, counters and atomics might be taken as a proof of concept. Making atom table mutable is surely possible nowadays without much hussle and without a huge performance penalty.
It is the GC which is the problem. If you want to garbage collect atoms then you need to do global GC which would either creates breaks in execution, which is totally unacceptable, or be very costly in memory or execution. @garazdawi in his answer goes through this.