Last active
October 31, 2019 12:42
-
-
Save blanchonvincent/6e9533a1c9443ac673ccd6065a0a1616 to your computer and use it in GitHub Desktop.
Medium - mark and sweep
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
type struct1 struct { | |
a, b int64 | |
c, d float64 | |
e *struct2 | |
} | |
type struct2 struct { | |
f, g int64 | |
h, i float64 | |
} | |
func main() { | |
s1 := allocStruct1() | |
s2 := allocStruct2() | |
func () { | |
_ = allocStruct2() | |
}() | |
runtime.GC() | |
fmt.Printf("s1 = %X, s2 = %X\n", &s1, &s2) | |
} | |
//go:noinline | |
func allocStruct1() *struct1 { | |
return &struct1{ | |
e: allocStruct2(), | |
} | |
} | |
//go:noinline | |
func allocStruct2() *struct2 { | |
return &struct2{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment