Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is a huge difference between GC.GetTotalMemory() and CLR Profiler numbers?

I have an object that I need to cache several of it for a web app in IIS so I am analyzing how much memory each instance use.

I wrote a small exe and I call GC.GetTotalMemory(true) before and after construction and the difference is around 335k but if analyze it in CLR profiler it shows me 22 MB of memory is used for the object which does not make sense.

What am I interpreting incorrectly in CLR profiler ?
Where should I check in profiler to see individual object sizes ?

like image 214
aziz Avatar asked Nov 14 '22 21:11

aziz


1 Answers

According to the MSDN: The garbage collector does not guarantee that all inaccessible memory is collected.

look here

CLR profiler shows all the memory allocated;

What if you use GC.GetTotalMemory(false) what is the result?

like image 194
Navid Rahmani Avatar answered Dec 19 '22 03:12

Navid Rahmani