how to measure memory consumption

  • Thread starter Thread starter Tom L
  • Start date Start date
How can I tell how much memory is being USED for each user session? :)
thanks!
 
there is no sure way, this will give an estimate:


double size = 0;
foreach (object obj in this.Session)
{
size += Convert.ToDouble(ObjectSizer.GetSize(obj));
}
Response.Write(string.Format("Session size: {0} KB",size / 1000));

class ObjectSizer
{
public static long GetSize(object obj)
{
MemoryStream m = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
try
{
b.Serialize(m, obj);
return m.Length;
}
finally
{
m.Close();
}
}
}


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top