using System.Diagnostics; using System.Text.Json; var held = Enumerable.Range(0, 8).Select(_ => new byte[100_000]).ToArray(); GC.Collect(2, GCCollectionMode.Forced, blocking: true); var info = GC.GetGCMemoryInfo(); using var process = Process.GetCurrentProcess(); Console.WriteLine(JsonSerializer.Serialize(new { observedAt = DateTimeOffset.UtcNow, runtime = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription, pid = Environment.ProcessId, workingSet = process.WorkingSet64, gcIndex = info.Index, heap = info.HeapSizeBytes, fragmented = info.FragmentedBytes, committed = info.TotalCommittedBytes, allocated = GC.GetTotalAllocatedBytes(false) })); Console.WriteLine("Different scopes: working set is process resident memory; GC fields describe the latest collection."); GC.KeepAlive(held);