struct 的某个 filed 被引用的时候 struct 本身就不会被垃圾回收器回收。
$ go run memtest.go -cpuprofile cpu.pprof -memprofile mem.pprof
$ go run memtest.go -cpuprofile cpu2.pprof -memprofile mem2.pprof -smallstruct
# 没有 pprof 工具需要安装一下
$ go get -u github.com/google/pprof
$ pprof -http=:8080 mem.pprof
$ pprof -http=:8081 mem2.pprof
big struct 占用 7G+ 内存
small struct 占用 3M+ 内存
- Getting to Go: The Journey of Go's Garbage Collector - The Go Blog
- Chris's Wiki :: blog/programming/GoInteriorPointerGC
- Does go GC keep whole objects in memory, while interior pointer to one field remains? Can this cause memory leaks? - Stack Overflow
- Does go's garbage collector support interior pointers? - Google 网上论坛
- Returning pointer on struct member or embedded struct in Go? - Stack Overflow
- Go: Should I Use a Pointer instead of a Copy of my Struct?
- Go语言101
- Go 语言原本
- 深入解析Go
- Go 语言设计与实现
- 第 83 期对 Go 程序进行可靠的性能测试 · Issue #564 · talk-go/night
test https://gist.github.com/binderclip/0f037c28f86970c8502a6c10c8f06dae