6

I'm learning Elixir and want to be sure I understand how garbage collection works in the Erlang VM.

My understanding is this:

  • Each VM-level process has its own heap
  • If that heap doesn't fill up before it terminates, it's discarded with the process and no GC is needed
  • Heaps that do fill up are garbage collected individually, in parallel, so GC doesn't "stop the world", just that one process

Is this correct?

Nathan Long
  • 122,748
  • 97
  • 336
  • 451

1 Answers1

15

Take garbage collection. When it's time to collect garbage in other languages, the entire system has to stop while the garbage collector runs. This approach is perfectly fine if your computer program is supposed to run once, write some output, and then quit. But in long-running applications, such as desktop, mobile, or server programs, this strategy results in occasionally frozen UIs and slow response times. Erlang programs, on the other hand, can have thousands of independent heaps which are garbage-collected separately; in this way, the performance penalty of garbage collection is spread out over time, and so a long-running application will not mysteriously stop responding from time to time while the garbage collector runs.

Evan Miller, creator of the popular Chicago Boss framework.

So I believe erlang garbage collects concurrently, that is, the various heaps are garbage collected independently of one another. Whether there is any parallelization depends on whether your node is running on multiple cores or not, but if so then the garbage collection is done in parallel, yes.

Michael Terry
  • 983
  • 11
  • 18
  • He didn't say no other languages have concurrent garbage collection. – Michael Terry Jul 22 '14 at 17:32
  • ... *in other languages*; does that mean one, many, all? Anyways, I don't think this is language specific. Garbage collection has evolved over time and still will evolve in future. The important point is that the Erlang GC supports concurrent GC, which answers the question. – artless noise Jul 22 '14 at 17:48
  • Ah, I gotcha. In this case, he was writing for experienced programmers, so they could be expected to know that VM and language features are virtually never unique. He was just emphasizing an erlang feature that's less common in popular alternatives and perhaps more battle-tested -- more about probabilities than absolutes. – Michael Terry Jul 22 '14 at 19:46
  • This video is a nice talk about some nice features that BEAM has: https://www.youtube.com/watch?v=_Pwlvy3zz9M&list=UUKrD_GYN3iDpG_uMmADPzJQ – Eduardo Jul 22 '14 at 23:10