Go 常见内存泄露
文章目录
常见内存泄露的情况
- 获取长字符串中的一段导致长字符串未释放
- 同样,获取长 slice 中的一段导致长 slice 未释放
- 在长 slice 新建 slice 导致泄漏
- goroutine 泄漏
- time.Ticker 未关闭导致泄漏
- Finalizer 导致泄漏
- Deferring Function Call 导致泄漏
内存泄露相关资料
- https://golang.org/pkg/runtime/#MemStats
- https://github.com/golang/go/issues/33684
- https://github.com/golang/go/issues/33376
- https://github.com/golang/go/issues/32284
- https://github.com/golang/go/issues/16843
- https://github.com/golang/go/issues/14521
- https://go101.org/article/memory-leaking.html
- http://play.golang.org/p/Nb39COQgxr
- https://www.freecodecamp.org/news/how-i-investigated-memory-leaks-in-go-using-pprof-on-a-large-codebase-4bec4325e192/
- https://medium.com/dm03514-tech-blog/sre-debugging-simple-memory-leaks-in-go-e0a9e6d63d4d
- https://github.com/golang/go/issues/16930
- https://github.com/golang/go/issues/30333
- https://go-review.googlesource.com/c/go/+/135395/
- https://github.com/golang/go/issues/23687
- https://ms2008.github.io/2019/06/30/golang-madvfree/
- https://golang.org/doc/go1.12#runtime