Why my golang app dont free mem to os

the top command show that RSS reach 280GiB.

malloc stats from golang:
`

HeapSys = 308454260736 = 287G
HeapAlloc = 166808725960 = 155G
HeapIdle = 138478010368 = 128G # why this part wont return to os
HeapInuse = 169976250368 = 158G # this part not matched with metrics in go pprof
HeapReleased = 13647872 = 13M
HeapObjects = 1108832654
`

Since requesting memory from the operating system is a costly operation (kernel call) Go will hold on to extra memory for some time, before returning it.

So Go can reuse the old memory if your code needs additional memory soon after releasing without additional kernel calls if the reserved memory fits.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.