You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"time"
)
func main() {
for i := 0; i < 5; i++ {
m := i
fmt.Println("outer: ", m)
go func(j int) {
k := j
fmt.Println("innter", k)
}(i)
}
time.Sleep(1 * time.Second)
s := "Done"
fmt.Println(s)
}
% go build --gcflags '-m -l' x.go
# command-line-arguments
./x.go:11:21: "outer: " escapes to heap
./x.go:11:21: m escapes to heap
./x.go:12:12: func literal escapes to heap
./x.go:12:12: func literal escapes to heap
./x.go:20:13: s escapes to heap
./x.go:14:25: "innter" escapes to heap
./x.go:14:25: k escapes to heap
./x.go:11:20: main ... argument does not escape
./x.go:20:13: main ... argument does not escape
./x.go:14:24: main.func1 ... argument does not escape
As we can see, the const strings, the variable j are allocated on heap, but they can be alloced on stack, by a easy manually check.
What did you expect to see?
the golang library funciton fmt.Println should not cause memory escape.
What did you see instead?
parameters passed into fmt.Println escaped to heap.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
As we can see, the const strings, the variable
j
are allocated on heap, but they can be alloced on stack, by a easy manually check.What did you expect to see?
the golang library funciton
fmt.Println
should not cause memory escape.What did you see instead?
parameters passed into
fmt.Println
escaped to heap.The text was updated successfully, but these errors were encountered: