A common mistake is to read a heap graph’s total for a function as memory allocated directly by that function. Follow the call chain: the total can include allocations made by functions it calls. section 12.8.1
Heap profiles sample allocations rather than recording every one. The default rate is one sample per 512 KB of heap allocation. Increasing sampling frequency collects more detail but requires more effort. section 12.8.1
Choose a sample type to match the question:
- alloc_objects and alloc_space count all objects and bytes allocated. section 12.8.1
- inuse_objects and inuse_space count objects and bytes not yet released. section 12.8.1
Trace an allocation total
A decode call accounts for 1,536 KB, or 6.32% of the heap total, but allocates none of it directly. The next decode call allocates 512 KB directly; another method accounts for the remaining 1,024 KB. section 12.8.1
$ go tool pprof -http=:8080 <file>
Download a profile from /debug/pprof/heap/?debug=0, then use this command with the downloaded file to inspect it in the pprof web UI. section 12.8.1
