![]() No object can go directly from the black set to the white set, which allows the algorithm to operate and be able to clear the objects in the white set.The objects of the white set are candidates for garbage collection. The objects of the grey set might have pointers to some objects of the white set.An object in the white set can have a pointer to an object of the black, because this has no effect on the operation of the garbage collector.The objects of black set are guaranteed to have no pointers to any object of the white set.The Primary principle behind the tricolor mark-and-sweep algorithm is that it divides the objects of the heap into three different sets according to their color, which is assigned by algorithm. This means that when a Go program runs, the Go scheduler is responsible for the scheduling of the application and the garbage collector as if the Go scheduler had to deal with a regular application with multiple goroutines! It can work concurrently with the program and uses a write barrier. The official name for the algorithms used in Go is the tricolor mark-and-sweep algorithm. The tricolor algorithms is not unique to Go, and it can be used in other programming languages as well. ![]() The operation of the Go garbage collector is based on the tricolor algorithm. There is a trick that allows you to get even more detailed output about the way the Go garbage collector operates, which is illustrated by the next command: 1 Allocation is done using size segregated per P allocation areas to minimize fragmentation while eliminating locks in the common case.įmt.Println( "mem.TotalAlloc:", mem.TotalAlloc)įmt.Println( "mem.HeapAlloc:", mem.HeapAlloc).It is non-generational and non-compacting.It is a concurrent mark and sweep that uses a write barrier.The GC runs concurrently with mutator threads, is type accurate(aka precise), allows multiple GC threads to run in parallel.The documentation of the Go garbage collector implementation states the following: This process happens in a concurrent manner while a Go program is running. The garbage collector sees which objects are out of scope and can no longer be referenced, and it frees the memory space they consume. Garbage Collection is the process of freeing memory space that is not being used.
0 Comments
Leave a Reply. |