Junior — Middle
Where in memory is an object created with the Make function stored?
sobes.tech AI
Answer from AI
The make function in Go is used to create slices, maps, and channels. Objects created with make are always allocated on the managed heap because they require dynamic memory allocation for their internal structures (e.g., a slice's underlying array or a map's hash table).
Example:
s := make([]int, 10) // slice of 10 elements
Here, a slice is created that points to an array in the heap, and the slice itself is a structure with a pointer, length, and capacity. The data the slice points to is stored in the heap.