1.goroutine结束后未被gc
2.确定是全局变量无回收
调用runtime.ReadMemStats可以看到Go的内存使用信息
使用go tool pprof -inuse_space http://127.0.0.1:6060/debug/pprof/heap?debug=2得到更细信息,其中HeapInuse为实际内存使用量
//引入pprof
import _"net/http/pprof"
//在main中加入
go func() {
log.Println(http.ListenAndServe("localhost:9999", nil))
}()
过context包来避免内存泄漏
# 参考:cnblogs.com/share-ideas/p/11365511.html