Published in
1 min readOct 5, 2024
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:
- Divide memory into stack & heap
- Non-moving
- Reference counting: roughly, exact detail unknown
- Partially stop-the-world (runs concurrently)
- Tweak by changing frequency (indirectly)
Java GC (G1):
- Divide memory into stack & heap; heap has multiple regions
- Moving: move objects between heap regions
- Reference counting: with many types of reference (weak, soft, phantom…)
- Stop-the-world
- Tweak by changing region size, GC type, pause time, frequency (indirectly, similar to Go GC)
Reference: