Last active
December 13, 2021 11:05
-
-
Save rustyx/e563a0254a68f53dd55ee2f76b70a91c to your computer and use it in GitHub Desktop.
A test for Go map growth issue #20135
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
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