I'm looking over the outcome of some simple C# code that just adds 10 mil elements to an ArrayList (efficiency is not the point, I just needed something that triggers GCs).
.NET Framework 4.7.2 is used. GC is running in the default Concurrent Workstation mode, on a Windows 10 x64 OS.
BenchmarkDotNet (BDN) is used to profile the code and PerfView runs at the same time to collect GC info. I simply mention BDN since the induced GCs seen before and after the code runs are actually coming from it; it plays no other role in the problem at hand.
Looking over PerfView's GCStats data, and focusing only on one single run of the code, we get this output:
Let's take a closer look for what happens during the last background GC (2B
), from within PerfView, by looking at the ETW events themselves:
As expected, the gen2 GC triggers both a gen0 (red highlight) and a gen1 GC (green highlight). Also, from Konrad Kokosa's book, "Pro .NET Memory Management": "Foreground GCs are regular Non-Concurrent GCs, during which Background GC is temporarily suspended"
In this context, why isn't the gen0 GC - reported as NonConcurrentGC - actually marked as ForegroundGC, just as the gen1 GC is ?
It's not a one-off thing either: the pattern of the BGC gen2 triggering one non-concurrent gen0 and a foreground gen1 GC is repeated.