Analyzing goroutine heap allocations (leak)

103 views
Skip to first unread message

Gavra

unread,
Feb 23, 2025, 7:12:14 AMFeb 23
to golang-nuts
Hi,
I have a heap profile that shows that many allocations are generated in a function that runs in a go routine. Unfortunately, I can't see the caller(s) to this function, implying I cannot detect the one holding the reference (and causing the mem leak).
1. Can I extract this information from the heap profile?
2. If not, can I take a heap profile that will gather this info?
3. Why isn't this info available by default? When the go routine is created, the runtime has all necessary context to indicate the trace call and forward it, shouldn't it always be the behavior?

Thanks.

Jan Mercl

unread,
Feb 23, 2025, 8:22:27 AMFeb 23
to Gavra, golang-nuts
You can try something like (adjust the args as needed)

$ go test -run nothing -bench . -memprofile mem.out -memprofilerate 1 -benchtime 4s
$ go tool pprof -lines -web -alloc_space *.test mem.out

HTH

Gavra

unread,
Feb 24, 2025, 3:20:26 AMFeb 24
to golang-nuts
I am not sure I understand. I have the issue reproducing only in production on a running instance...

Jan Mercl

unread,
Feb 24, 2025, 3:35:27 AMFeb 24
to Gavra, golang-nuts
On Mon, Feb 24, 2025 at 9:20 AM Gavra <gav...@gmail.com> wrote:

> I am not sure I understand. I have the issue reproducing only in production on a running instance...

Not mentioned in the OP. You can still try to write tests and/or
benchmarks that exhibit the same memory leak and then use them with
the -memprofile facility.
Reply all
Reply to author
Forward
0 new messages