Investigating suspected memory leak based on StackInUse

Hi.

I’m trying to find a memory leak in my application.
I’ve added some runtime memory stats to the logs (Heap & Stack stats).
I can see that from time to time m.StackInuse is increasing without any obvious reason from the application prespective.
Here some additional runtime mem stats (Taken at the same time):
StackInUse 56MB
HeapSys: 147MB.
HeapAlloc: 97MB

While StaackInUse and HeapSys seems to increase from time to time, HeapAlloc stays about the same during 6 hours while the application is running.
There seems to be a bit of corelation between StackInUse and HeapSys, but overtime StackInUse increase more than HeapSys. (Is HeapSize includes StackInUse?)

In addition to adding runtime memory logs, I’m also creating periodic heap profile dumps.
My problem is that when analyzing the heap with pprof, it gives me no clue why StackInUse is so high.
The pprof inuse_space shows:
“Showing nodes accounting for 55.31MB, 93.25% of 59.31MB total”
What this total MB represent? It doesn’t seem to match HeapAlloc, HeapSys or StackInUse.
Does pprof heap profile even include StackInUse?

I really need to understand where the leak is coming from, but after looking in many places, the memory stats are still not clear to me, and neither what memory stat pprof heap profile really represent.
Note that I’m also logging HeapObjects count and I don’t see any leak there… It’s just StackInUse increasing from time to time, and HeapSys.

Note that I’m also using Cgo, but my understanding is Cgo memory allocations will not be reflected by the runtime memory stats. Is this correct and I assume if runtime memory stats are increasing this is defiantly because of go code and not C code?
I hope I was clear, but added a screenshot for the different memory stats.
Marked in red the point in times that stackInUse increase. (My current understanding which might be wrong, is that stackInUse is not included in HeapSys, this is why they are stacked in the graph)

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