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
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
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
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.
Popular in Thoughts On...
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








