关于此代码的问题。为什么变量逃逸到堆
func main() {
port := "8080"
host := "localhost:"
connection := host + port
fmt.Println(connection)
}
gorun -gcflags "-m -l" main.go
# command-line-arguments
./main.go:12:21: host + port escapes to heap
./main.go:13:13: ... argument does not escape
./main.go:13:13: connection escapes to heap
我发现如果使用fmt.Sprintf
它也会导致变量逃逸到堆