Preston Pham
Mango Tree
Published in
1 min readOct 5, 2024

--

a colorful painting of a farmer (wearing Golang shirt) collecting fallen mangos under a mango tree in the style of 1800s, pixel art

Recently I needed to check how Go GC works. Of course, the best source for that would be Go official documentation. The page contains the right level of detail for developers who want to take advantage of the GC. But this level of detail is more than I need for my current goal.

I was looking for a high-level overview without needing to adjust specific settings. Additionally, I still remember Java GC from tweaking it some time ago so why not learn based on what I already know.

I then came up with this short comparison.

Go GC:

  1. Divide memory into stack & heap
  2. Non-moving
  3. Reference counting: roughly, exact detail unknown
  4. Partially stop-the-world (runs concurrently)
  5. Tweak by changing frequency (indirectly)

Java GC (G1):

  1. Divide memory into stack & heap; heap has multiple regions
  2. Moving: move objects between heap regions
  3. Reference counting: with many types of reference (weak, soft, phantom…)
  4. Stop-the-world
  5. Tweak by changing region size, GC type, pause time, frequency (indirectly, similar to Go GC)

--

--