Skip to content

Instantly share code, notes, and snippets.

@blanchonvincent
Last active October 31, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blanchonvincent/6e9533a1c9443ac673ccd6065a0a1616 to your computer and use it in GitHub Desktop.
Save blanchonvincent/6e9533a1c9443ac673ccd6065a0a1616 to your computer and use it in GitHub Desktop.
Medium - mark and sweep
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