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
It seems that calling runtime.KeepAlive causes the argument to escape:
package main
import "runtime"
func f(s string) {
runtime.KeepAlive(s)
}
func main() {
f("hello")
}
// ./test.go:5:6: can inline f
// ./test.go:9:6: can inline main
// ./test.go:10:3: inlining call to f
// ./test.go:6:19: s escapes to heap
// ./test.go:5:10: leaking param: s
// ./test.go:10:3: s escapes to heap
Bizarrely, if I change the definition of KeepAlive to give the parameter a name:
package main
import "runtime"
func f(s string) {
runtime.KeepAlive(s)
}
func main() {
f("hello")
}
// ./test.go:5:6: can inline f
// ./test.go:9:6: can inline main
// ./test.go:10:3: inlining call to f
// ./test.go:5:10: f s does not escape
// ./test.go:6:19: f s does not escape
// ./test.go:10:3: main s does not escape
What version of Go are you using (
go version
)?I see this on Go 1.8 and also tip. The examples below were run with tip.
What operating system and processor architecture are you using (
go env
)?linux/amd64
See original context here: https://groups.google.com/d/msg/golang-nuts/dcjzJy-bSpw/6yntq3OVBQAJ
It seems that calling runtime.KeepAlive causes the argument to escape:
Bizarrely, if I change the definition of KeepAlive to give the parameter a name:
then the argument doesn't escape:
@randall77 @ianlancetaylor
The text was updated successfully, but these errors were encountered: