garbage collections on Windows and Mac

100 views
Skip to first unread message

Michael Mitchell

unread,
Jan 9, 2024, 10:21:26 PM1/9/24
to golang-nuts
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.

 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? 




Michael Knyszek

unread,
Jan 10, 2024, 2:15:45 AM1/10/24
to golang-nuts
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.
Reply all
Reply to author
Forward
0 new messages