Skip to content

Instantly share code, notes, and snippets.

@rustyx
Last active December 13, 2021 11:05
Show Gist options
  • Save rustyx/e563a0254a68f53dd55ee2f76b70a91c to your computer and use it in GitHub Desktop.
Save rustyx/e563a0254a68f53dd55ee2f76b70a91c to your computer and use it in GitHub Desktop.
A test for Go map growth issue #20135
package main
import (
"fmt"
"runtime"
)
func main() {
mymap := make(map[string]*string)
for i := 0; i < 1000000001; i++ {
newkey := fmt.Sprintf("key_%d", i)
mymap[newkey] = &newkey
oldkey := fmt.Sprintf("key_%d", i-25)
delete(mymap, oldkey)
if i%1000000 == 0 {
runtime.GC()
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("map = %v, alloc = %v, heap = %v, sys = %v\n", len(mymap), m.Alloc, m.HeapAlloc, m.Sys)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment