I have a Golang program that just implements a simple business logic: establish a socket connection with the server-side program and maintain a business heartbeat. But when this connection does not transmit task data, the pprof report shows that HeapAlloc is about 14MB, but inuse_space shows that it is only 512KB. What is the reason for such a big difference?
pprof HeapAlloc:
# runtime.MemStats
# Alloc = 1386704
# TotalAlloc = 49178232
# Sys = 15285372
# Lookups = 0
# Mallocs = 497504
# Frees = 494691
# HeapAlloc = 1386704
# HeapSys = 12124160
# HeapIdle = 9830400
# HeapInuse = 2293760
# HeapReleased = 8552448
# HeapObjects = 2813
# Stack = 458752 / 458752
# MSpan = 25680 / 32768
# MCache = 1736 / 16384
# BuckHashSys = 727065
# GCSys = 1149056
# OtherSys = 777187
# NextGC = 4194304
# LastGC = 1645580268115312488
go tool pprof mem.prof:
Type: inuse_space
Time: Feb 23, 2022 at 10:23am (CST)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top5
Showing nodes accounting for 513.12kB, 100% of 513.12kB total
flat flat% sum% cum cum%
513.12kB 100% 100% 513.12kB 100% compress/flate.(*huffmanEncoder).generate
0 0% 100% 513.12kB 100% compress/flate.init.0
0 0% 100% 513.12kB 100% runtime.doInit
0 0% 100% 513.12kB 100% runtime.main