erlang 为什么原子不是BEAM收集的垃圾?

7y4bm7vi  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(105)

好吧,标题说明了一切:我想知道为什么BEAM不垃圾收集原子。我知道问题How Erlang atoms can be garbage collected,但是,虽然相关,它没有回答 * 为什么 *。

rks48beu

rks48beu1#

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.

相关问题