You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GC.GetTotalMemory looks like it counts gen1/gen2 twice on the segments GC (macOS) #134755
On macOS, GC.GetTotalMemory returns much more than the live heap. In the repro below the small objects seem to be counted twice, while the LOH array is counted once. We noticed it because a memory test reads about 2x on macOS compared to Linux for the same allocations.
With DOTNET_GCName=libclrgcexp.dylib (regions) on the same Mac the numbers match, and with libclrgc.dylib (segments) they don't, so I think it's specific to the segments GC.
I think so, since .NET 7. It looks like it came from the ApproxTotalBytesInUse rewrite in #59283 (Enable GC regions by default). On the segments path gen0 is measured from the start of the ephemeral segment:
In a small heap gen1 and gen2 live on that same segment, so they're already included, and then the loop adds generation_size (1) and generation_size (2) on top. The .NET 6 version counted the ephemeral segment once and only added the other gen2 segments. I haven't run the repro on .NET 6 though, this is from reading the code.
Other information
#125416 (Enable GC regions on macOS) should make this go away on macOS in .NET 11, but the segments code path is unchanged in main, so I'd guess other segments builds (standalone clrgc, 32-bit) still have it. Since macOS stays on segments for all of .NET 10, could a fix be considered for .NET 10 servicing?
Activity
dotnet-policy-service commentedon Sep 27, 2026
Tagging subscribers to this area: @anicka-net, @dotnet/gc
See info in area-owners.md if you want to be subscribed.
Fix segment GC total memory accounting (#134851)
Fix flaky AhoCorasick memory test on win-x86 by not using GC.GetTotal…
Fix flaky AhoCorasick memory test on win-x86 by not using GC.GetTotal…