fireproofsocks

fireproofsocks

Is there a way to tell if an atom exists?

Is there a way to tell if an atom already exists? If I’m thinking about this correctly, if you already “have” an atom somewhere in your code, then it must already exist because it was parsed. In other words, if you had something like is_existing_atom(:foo), then the atom :foo must already exist because it was summoned into existence when that code got parsed – is that right?

For context, the reason I started thinking about this was while working on a long-running job processor that spins up a lot of processes over time. I realized that if I provide a name to these processes (i.e. a name provided to the Agent or Genserver, or even more generically a name registered via Process.register/2), then I might get into trouble because atoms are not garbage collected: if my app ran long enough and processed enough jobs, then the VM might crash given enough unique process names. I think that’s a valid concern, but someone correct me if I’m wrong.

To avoid getting into VM trouble down the road by registering too many atoms (and I realize I may not hit that limit in the confines of normal operation), one solution might be to store a map that would connect a string ID to a pid (e.g. in ETS). The advantage would be I could easily delete keys that were no longer relevant; the disadvantages would be the necessity to manage an ETS table and deal with the cleanup of keys that point to dead pids.

FYI: The closest related function here is String.to_existing_atom/1 which I will include for searches.

Marked As Solved

nhpip

nhpip

You can dump the atom table. Do Atom.to_term so you can compare against a string. Not the best solution I agree

Also Liked

LostKobrakai

LostKobrakai

You can use arbitrary keys with Registry.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement