Search code examples
c#azurekubernetes.net-coreazure-aks

GC.GetTotalMemory(false) vs Container Memory Working Set question (Azure AKS, .NET Core 5)


I have a container with a dotnet core application running in Azure Kubernetes Service. No memory limits were specified in Pod specs.

The question is why GC.GetTotalMemory(false) shows approx. 3 Gb of memory used while AKS Insights shows 9.5 GB for this Pod container?

enter image description here

enter image description here

Running top reveals these 9.5 GB: enter image description here


Solution

  • As I understand GC.GetTotalMemory(false) returns the size of managed objects in bytes but the entire working memory set is much larger because memory is allocated in pages and because of managed heap fragmentation and because GC is not performed.