The tricolor algorithm

The operation of the Go garbage collector is based on the tricolor algorithm.

Please note that the tricolor algorithm is not unique to Go and can be used in other programming languages.

Strictly speaking, the official name for the algorithm used in Go is the tricolor mark-and-sweep algorithm. It can work concurrently with the program and uses a write barrier. This means that when a Go program runs, the Go scheduler is responsible for the scheduling of the application and the garbage collector. This is as if the Go scheduler has to deal with a regular application with multiple goroutines! You will learn more about goroutines and the Go scheduler in Chapter 9, Concurrency in Go – Goroutines, Channels, and Pipelines ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.