METHOD
GC.GetTotalAllocatedBytes
Returns cumulative managed allocation bytes for the process. The default approximate mode can differ from a precise observation; precise collection can be costly. This is not retained heap size, native allocation, or a per-request measurement.
Formal Syntax & Structure
csharp syntaxcsharp
GC.GetTotalAllocatedBytes(precise: false)Working Example
Example Snippetcsharp
using System;using System.Linq;using System.Diagnostics;using System.Diagnostics.Metrics;long allocated=GC.GetTotalAllocatedBytes(); Console.WriteLine(allocated>=0); // True; actual count varies