Please enable JavaScript.
Coggle requires JavaScript to display documents.
Golang - Coggle Diagram
Golang
Memory management
Heap
Garbage collector (GC)
Mark & Sweep
Mark
Tri-color algorithm
Black
are guaranteed to have no pointers to any object of the white set
Gray
might have pointers to some objects of the white set
White
are the candidates for garbage collection
Sweep
White memory block
collect only if is not referenced i.e. unused memory blocks
GOGC
starts GC when a threshold is satisfied
Using SetGCPercent (package runtime/debug) function GOGC can be set
default GOGC=100 and negative percentage disables garbage collection
the ratio of freshly allocated data to live data remaining after the previous collection
Package-level allocated memory variables will never be collected
can be used by multiple goroutines
uses OS function mmap similar to TCMalloc (Thread-Caching Malloc) to allocate memory in heap
Stack
Goroutine
maintain a small stack (memory segment) act as memory pool for some memory blocks
The maximum stack size is 1 GB on 64-bit systems, and 250 MB on 32-bit systems
can be set by SetMaxStack function
collected automatic (not by garbage collector) while exiting