packagemain
import(
"fmt"
"runtime"
)
constN = 128
funcrandBytes() [N]byte{
return[N]byte{}
}
funcprintAlloc() {
varm runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("%d MB\n", m.Alloc/1024/1024)
}
funcmain() {
n := 1_000_000
m := make(map[int][N]byte, 0)
printAlloc()
fori := 0; i < n; i++ {
m[i] = randBytes()
}
printAlloc()
fori := 0; i < n; i++ {
delete(m, i)
}
runtime.GC()
printAlloc()
runtime.KeepAlive(m)
}