Question

I ask because

  1. there doesn't seem to a be a good way to represent Pids in a way that can be encoded in JSON (for trading messages with a web-based client),
  2. it would therefore be convenient to register processes that represent these messages to the client using an alternate identifier of some kind, like a serial number or timestamp, however
  3. processes are registered using atoms, and
  4. although names are "unregistered" when their processes die,
  5. atoms in the Erlang VM are not garbage collected.

So registering a large number of processes consumes memory that is never recovered, right? Or does unregistering the name also clean up the atom?

Was it helpful?

Solution 2

The atom is never cleaned up and you will eventually run out of atoms.

What is the problem with Pids in json? Can't you just use a string?

{
    "pid": "<0.12.0>"
}

OTHER TIPS

You could use the gproc application instead of the register function. Gproc allows you to use arbitrary erlang terms (e.g. a string) as the process alias.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top