Is there a way to programmatically and accurately determine the amount of memory used by an object in c#? I am not concerned with how slow the process is, so running GCs left a
object obj = new List(); // whatever you want to get the size of
RuntimeTypeHandle th = obj.GetType().TypeHandle;
int size = *(*(int**)&th + 1);
Console.WriteLine(size);
I dont know whether it is useful to you or not...but try to refer this link...espacialy fig.4
http://msdn.microsoft.com/en-us/magazine/cc163791.aspx#S9