NOTE

make vs new in Go

Allocation and initialization differences between new and make.

GoCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

new(T) returns *T pointing to a zero value of T. It does not imply heap allocation; escape analysis decides where storage lives.

make initializes the runtime backing structures of slices, maps, and channels and returns the value itself rather than a pointer to it. Use literals/constructors when they communicate intent more clearly; both built-ins are ordinary language mechanisms, not manual-memory-management APIs.

Loading helpful count