Garbage collection
Before garbage-collected languages, we needed to handle memory management ourselves. Despite the focused attention that this discipline craves, the main problems we ran in circles to avoid were memory leaks, dangling pointers, and double frees.
The garbage collector in Go has some jobs to avoid common mistakes and accidents: it tracks allocations on the heap, frees unneeded allocations, and keeps the allocations in use. These jobs are commonly referred to in academia as memory inference, or “What memory should I free?”. The two main strategies for dealing with memory inference are tracing and reference counting..
Go uses a tracing garbage collector (GC for short), which means the GC will trace objects reachable by a chain of references from “root” objects, consider the rest as “garbage,” and collect them. Go’s garbage collector has a long journey of optimization and learning. You can find the whole path to today...