Skip to content

Instantly share code, notes, and snippets.

@blanchonvincent
Last active September 18, 2019 20:20
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/dfa2ecd831080488afdd8893423de728 to your computer and use it in GitHub Desktop.
Save blanchonvincent/dfa2ecd831080488afdd8893423de728 to your computer and use it in GitHub Desktop.
Medium - Garbage Collector
func BenchmarkAllocationEveryMs(b *testing.B) {
// need permanent allocation to clear see when the heap double its size
var s *[]int
tmp := make([]int, 1100000, 1100000)
s = &tmp
var a *[]int
for i := 0; i < b.N; i++ {
tmp := make([]int, 10000, 10000)
a = &tmp
time.Sleep(time.Millisecond)
}
_ = a
runtime.KeepAlive(s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment