烙印99
不会释放value,仅仅标记为不可用,但实际内存还是在占用1234567891011121314151617181920212223242526272829303132333435363738394041424344package main import ( "log" "runtime") var intMap map[int]intvar cnt = 8192 func main() { printMemStats() initMap() runtime.GC() printMemStats() log.Println(len(intMap)) for i := 0; i < cnt; i++ { delete(intMap, i) } log.Println(len(intMap)) runtime.GC() printMemStats() intMap = nil runtime.GC() printMemStats()} func initMap() { intMap = make(map[int]int, cnt) for i := 0; i < cnt; i++ { intMap[i] = i }} func printMemStats() { var m runtime.MemStats runtime.ReadMemStats(&m) log.Printf("Alloc = %v TotalAlloc = %v Sys = %v NumGC = %v\n", m.Alloc/1024, m.TotalAlloc/1024, m.Sys/1024, m.NumGC)}