Junior — Middle
Where does the runtime get allocated memory at startup?
sobes.tech AI
Answer from AI
A goroutine in Go gets its dedicated memory from a stack managed by the Go runtime. Unlike traditional threads, goroutines initially have a very small stack (usually a few kilobytes), which can dynamically grow and shrink as needed.
When a new goroutine is created, the runtime allocates a small stack for it on the heap, and then increases its size if necessary. This allows thousands or even millions of goroutines to run with minimal memory consumption.
Thus, the memory for a goroutine is allocated from the runtime-managed memory area, not directly from the system stack.