1

I'm looking for a way to count all live objects in heap, grouped by type. Seeing the size of the objects would be a bonus.

Use case: See why my application needs 36 GB of heap while the size of the data it's holding should be only 5 GB.

I haven't been able to figure out how to do it with pprof. Looks like it only counts allocations, not objects in heap.

In VisualVM (for JVM), a memory snapshot shows this information straight away:

VisualVM objects list

  • 1
    This may be related: https://stackoverflow.com/questions/24863164/how-to-analyze-golang-memory – Jessie Mar 13 '23 at 18:54
  • 1
    I don't think there is any way to see heap objects grouped by type. I'm not aware of any way to see live heap objects at all actually - I don't think Go indexes memory that way. You can use a profiler to see where in the code memory allocations happen, and from that infer what type of objects are being allocated often. – Adrian Mar 13 '23 at 21:23

0 Answers0