Why are atoms not garbage collected by the BEAM?

302 Views Asked by At

Well, the title says it all: I'm wondering what is the reason why the BEAM doesn't garbage collect atoms. I'm aware of question How Erlang atoms can be garbage collected but, while related, it doesn't reply to why.

1

There are 1 best solutions below

1
On BEST ANSWER

Because that is not possible (or at least very hard) to do in the current design. Atoms are important part of:

  • modules, as module names are atoms
  • function names, which also are atoms
  • distributed Erlang also extensively use atoms

Especially last point makes it hard. Imagine for second that we would have a GC for atoms. What would happen if there would be a GC cleanup in between the distributed call where we send some atoms over the wire? All of that makes atoms quite essential to how VM works and making them GCed would not only make implementation of VM much more complex, it would also make code much slower as atoms do not need to be copied between processes and as these aren't GCed, these can be completely omitted in GC mark step.