#2096·delve

[feature request] coredump, show estimated memory usage / number of children objects recursively (object's total retained size)

Author: balta2arCreated Jul 6, 2020Updated May 28, 2025
Labelskind/enhancementkind/discussion

When it comes to memory leaks, heap profile is a useful tool to see where memory was allocated. However, that's only partly helpful because the profile shows where memory was allocated but it doesn't show where memory is currently referenced. coredump of a process is another view at the data, and delve helps greatly to look into it. The inconvenience is that if you're tracking memory leaks and you're unfamiliar with the code base, you can find leaking objects (e.g. slices or maps that are being appended to but never removed), but you need to know exactly where to look for. Alternatively, you have to check every goroutine, every stack frame of it, and all the local variables in each stack frame's local variable list, which can be tedious and time-consuming.

What I propose is to add some sort of summary to each object (including a goroutine, a stack frame, and a variable) that would tell the number of the child objects and total memory size, so that you can have an overview of the goroutnies/stack frames/and variables that take most of the memory and you could easily drill down into a goroutine -> stack frame -> leaking variable. Very similarly to how disk usage apps show this information, but for variables and memory here.

It was suggested that viewcore could be a tool for that (https://github.com/golang/go/issues/34561#issuecomment-536646220), but in practice delve shows type information much better than viewcore.

Ideally, this could be a part of gdlv UI, but it could also work as a starlark command. I'm not sure, maybe what I want it possible using Variable API and this example https://github.com/go-delve/delve/blob/master/Documentation/cli/starlark.md#print-all-elements-of-a-linked-list?