i know this article may seems duplicate but i read all of this articles and develop a sample to test theme
Find size of object instance in bytes in c# http://www.codeproject.com/Questions/177604/Size-of-a-class-in-c How to get object size in memory? Getting the size of a field in bytes with C# http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51326.aspx
i have a class whiteout any properties or field, it is empty just to test size of it.
[Serializable]
public class MemberStateModel
{
}
i create a object and get size of it by bellow codes:
static void Main(string[] args)
{
MemberStateModel o = new MemberStateModel() {};
long size;
using (Stream s = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(s, o);
size = s.Length;
}
}
now in size it shows number 159, by that posts i think it means my o size is 159kbyte but i think its not correct way and an empty object can not has this size, is it true?
it's very important for me because i store some user's data in session and if this size grows up by Added users in my site, i will need more physically memory to handle my web application