$ go version
go version devel +377a2cb2d2 Tue Mar 27 18:03:39 2018 +0000 linux/amd64
When compiling
package p
func f() {
n := 32
workBuf := make([]int, 0, n)
// ... do some local work on workBuf
_ = workBuf
}
-m -m says:
./test.go:5:17: make([]int, 0, n) escapes to heap
from make([]int, 0, n) (too large for stack) at ./test.go:5:17
The given reason for the escape ("too large for stack") is wrong. The same-sized allocation is put on the stack when the bound is a const 32:
./test.go:5:17: f make([]int, 0, 32) does not escape
The real reason for the escape is that we don't stack-allocate arrays when the len/cap is a variable.
Someone using -m -m when investigating an allocation profile may be thrown off by the incorrect explanation.
When compiling
-m -msays:The given reason for the escape ("too large for stack") is wrong. The same-sized allocation is put on the stack when the bound is a
const32:The real reason for the escape is that we don't stack-allocate arrays when the len/cap is a variable.
Someone using
-m -mwhen investigating an allocation profile may be thrown off by the incorrect explanation.