Created
November 22, 2023 10:06
-
-
Save yumed15/eec0a6b8ffad4d0fee866f9d9d399638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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