On Tuesday, January 9, 2024 at 10:21:26 PM UTC-5 Michael Mitchell wrote:

Hi,

I have noticed on my macbook pro that HeapInUse is always slightly above 
NextGC when the garbage collection occurs.  

According to mstats.go, the "garbage collector's goal is to keep HeapAlloc 
less than NextGC" and also  according to mstats.go, "HeapInUse minus 
HeapAlloc estimates the amount of memory that has been dedicated to 
particular size classes, but is not currently being used" so it makes 
sense   that HeapInUse rises above NextGC, and also that HeapIdle gets 
smaller as we get closer to NextGC. 

However, on my windows machine, as shown in this attached video, the 
garbage collections are occuring well below the NextGC level.  When the 
number of garabge collections changes from 4 to 5, the number of 
Allocations is well below the nextGC level.
https://youtube.com/shorts/jf6DoEQSnMk?feature=share

 On both the Mac and Windows machine, the nextGC level is the same. 

Question: Why is the garbage collection happening much sooner on the 
Windows than the Mac? 

It may not be. It may be an artifact of how the MemStats values are being 
read or possibly a bug in the stats. What is the output of your program 
when you set GODEBUG=gctrace=1 in your environment? I briefly 
double-checked some runtime tests that exercise the GC on a Windows machine 
and everything looked fine (the GC ended at about the right time 
consistently) with the GODEBUG=gctrace=1 output. (I only checked that 
because it was easier to do, and those numbers are come from values much 
closer to the source-of-truth in the GC.) If you are able to share the 
program that produced the output and also the version of Go that you used, 
that would be helpful.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/58198399-7842-48c6-82a2-5bf340530ddcn%40googlegroups.com.

Reply via email to