Skip to content

Instantly share code, notes, and snippets.

@yumed15
Created November 22, 2023 10:06
Show Gist options
  • Save yumed15/eec0a6b8ffad4d0fee866f9d9d399638 to your computer and use it in GitHub Desktop.
Save yumed15/eec0a6b8ffad4d0fee866f9d9d399638 to your computer and use it in GitHub Desktop.
func closure1() {
var x *int
func(x1 *int) {
func(x2 *int) {
func(x3 *int) {
y := 1
x3 = &y
}(x2)
}(x1)
}(x)
_ = x
}
func closure2() {
var x *int
func() {
func() {
func() {
// y escapes to heap
y := 1
// x is captured by a closure
x = &y
}()
}()
}()
_ = x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment