package main
import "fmt"
func TestScope() []int {
a := make([]int, 0, 10)
return a
}
func TestScopeCore() {
b := TestScope()
fmt.Println(b)
}
我运行
go tool compile -m headp.go
得到的结果:
headp.go:12:6: can inline TestScope
headp.go:18:16: inlining call to TestScope
headp.go:19:13: inlining call to fmt.Println
headp.go:13:11: make([]int, 0, 10) escapes to heap
headp.go:18:16: make([]int, 0, 10) escapes to heap
headp.go:19:13: b escapes to heap
headp.go:19:13: []interface {}{...} does not escape
<autogenerated>:1: leaking param content: .this
我不大明白为啥make([]int, 0, 10)这里逃逸了两次,还请大神赐教啊