「34」Go memory leak about RSS
¶前序:
今天收到了封邮件 Go 1.16 release:
进去了看了看全部的特性,发现有个关于memory leak「RSS」相关的issues,去看看关于Go的RSS到底是怎么计算的,
顺带也看看这个老哥为何会问内存泄露的问题.
¶问题:
runtime: memory leaked observed in go program #40448
¶简述起因:
一个tcp接受程序导致RSS不断上升.
这个起了5个goroutine协程来处理请求,但是请求处理结束后,RAM并没有趋于稳定或者降低.导致了看似的memory leak.
- 描述:
¶关于RSS解释
1 | The current minimum heap size of a Go program is 4mb. In addition to this the operating system threads that back goroutines should be added to that as well as some non heap memory used by the runtime. In your case this may be somewhere between 7 and 9mb. |
¶解决办法
- runtime/debug.SetGCPercent (设置gc的百分比,-1为不GC)
- runtime.GC (调用系统GC)
- runtime/debug.FreeOSMemory (accelerate the pace of returning unused pages to the OS)
¶其它方面的问题
从这里看的话,其实这个哥们的问题并不属于go的bug,只是说对于内存使用的理解有偏差,
觉得go运行时环境很像是unix系统,内存有多少用多少,不会是用完就释放给系统.
毕竟有句话: 空间换时间