W3NDO

W3NDO

Understanding why atoms are not garbage collected

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.

I went further and learned that in the older ruby days(ruby < 2.2) there was also a possibility of symbol exhaustion(https://stackoverflow.com/questions/16621073/when-to-use-symbols-instead-of-strings-in-ruby).

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?

Most Liked

mudasobwa

mudasobwa

Creator of Cure

There is no such thing as “Elixir atom,” it’s rather “Erlang atom.”

There is a very descriptive answer to your question by one of Erlnag core team members.

rvirding

rvirding

Creator of Erlang

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.

mudasobwa

mudasobwa

Creator of Cure

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.

The question is whether it’s really needed.

Where Next?

Popular in Thoughts On... Top

pera
Releases is a fantastic new feature in Elixir 1.9, but it comes with one important caveat: Once a release is assembled, it can be packa...
New
W3NDO
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 ...
New
mszmurlo
Recently ‘discovered’ the reduce: option for comprehensions. Very useful, yet there is a syntax difference between into: and reduce: that...
New

Other popular topics Top

msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement