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

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
Tee
can someone please explain to me how Enum.reduce works with maps
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
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
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
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 42633 214
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

We're in Beta

About us Mission Statement