Garbage Collection
Explore how Go's garbage collector operates concurrently to free unused memory during program execution. Understand key metrics like heap allocation and garbage collection cycles using practical runtime examples, and learn to optimize memory usage and performance in Go applications.
We'll cover the following...
Garbage collection is the process of freeing up memory space that is not being used. In other words, the GC sees which objects are out of scope and cannot be referenced anymore and frees the memory space they consume. This process happens in a concurrent way while a Go program is running and not before or after the execution of the program. The documentation of the Go GC implementation states the following:
“The GC runs concurrently with mutator threads, is type accurate (also known as precise), and allows multiple GC threads to run in parallel. It is a concurrent mark-and-sweep that uses a write barrier. It is non-generational and non-compacting. Allocation is done using size segregated per P allocation areas ...