I am trying to debug why a byte slice is escaping in my program. I have a small reproducible example here:
% cat escape.go
package main
func main() {
x := make([]byte, 5)
y := new([]byte)
*y = x
nothing((*y)[3])
}
func nothing(b byte) {}
% go tool compile -m -m -l escape.go
escape.go:4:11: make([]byte, 5) escapes to heap:
escape.go:4:11: flow: x = &{storage for make([]byte, 5)}:
escape.go:4:11: from make([]byte, 5) (spill) at escape.go:4:11
escape.go:4:11: from x := make([]byte, 5) (assign) at escape.go:4:4
escape.go:4:11: flow: {heap} = x:
escape.go:4:11: from *y = x (assign) at escape.go:6:5
escape.go:4:11: make([]byte, 5) escapes to heap
escape.go:5:10: new([]byte) does not escape
It seems to me like neither x nor it's backing array should escape, but I'm having trouble figuring out why it's flagged as escaping from the debug output.
Any help would be appreciated.