PHP has the function memory_get_usage
to report the amount of memory a PHP script has. How can you do the same thing in .NET (ASP.NET C#)?
Also, can you report on how much memory an object is taking (e.g. SiteMap or DataTable)?
For your current process you can use
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
long privateMemory = currentProcess.PrivateMemorySize64;
and
long managedMemory = GC.GetTotalMemory(true);
which will report the amount of managed memory allocated.
Getting the size for value types can be done with
var size = sizeof(int);
For an arbitrary object it's a bit more tricky since it can consist of many smaller objects of unknow size.
Also see