In software engineering, a garbage collector is a form of automated memory management that frees memory that was allocated by a program but is no longer needed.

The problem is that garbage collection is an expensive process computationally. For instance, some languages effectively halt useful computation while the garbage collector scans through memory.

At Discord,1 their LRU caching mechanism used Go. But the garbage collector resulted in large latency spikes every 2 minutes (a consequence of the language runtime) that couldn’t be resolved without increasing tail latency. They decided to switch to Rust since it manages memory without GC.

Implementation

C/C++ don’t have built-in garbage collectors by default. We can instead use the Boehm-Demers-Weiser conservative garbage collector. Most other languages have built-in collectors (including Java, C#, and scripting languages like Python and JavaScript).

Footnotes

  1. From this blog post: Why Discord is switching from Go to Rust