Count Memory Sizes for Object graph

  • Thread starter Thread starter Angelos Karantzalis
  • Start date Start date
A

Angelos Karantzalis

Hi, I'm in a situation where I have a Web App that needs to load some xml
info in-memory, and keep it there throughout the lifetime of my application.

Since the Xml could get large (200K+) and I wouldn't ned to use any
xml-specific operations on it (modify it, or do XPaths, xslt or whatever) I
de-serialize the xml into an object graph.

My question is:
Can I find out exactly how much memory my object graph occupies ? I want to
make some comparisons between holding that into memory, and holding an
XmlDocument instead ( because of the Xml-related operations I could use in
case I held the XmlDocument, it might be worth the trade, but I can't judge
without first knowing the difference in memory consumption :? )

Thanks a lot guys,
Angel
O:]
 
you cannot do something like C's sizeof(x).

but you can use the perfmon and .NET CLR instrumentation to examine the size
of an item during development.
For example, check the memory size, then instantiate 100 instances of X,
then check the memory size again.

Compare to the situation with 100 instances of XmlDocument.

see here:
http://www.c-sharpcorner.com/Code/2002/May/PerformanceCountersP1.asp

also consider using a WeakReference:
http://www.cookcomputing.com/blog/archives/000103.html
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWeakReferenceClassTopic.asp
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx


This way you wouldn't have to decide whether the object is "too big" or not.
You can let the CLR decide for you! ;)

-D
 
Thanks a lot Dino, i'll definitely be checking both out :]

Angel
O:]


Dino Chiesa said:
you cannot do something like C's sizeof(x).

but you can use the perfmon and .NET CLR instrumentation to examine the size
of an item during development.
For example, check the memory size, then instantiate 100 instances of X,
then check the memory size again.

Compare to the situation with 100 instances of XmlDocument.

see here:
http://www.c-sharpcorner.com/Code/2002/May/PerformanceCountersP1.asp

also consider using a WeakReference:
http://www.cookcomputing.com/blog/archives/000103.html
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWeakReferenceC
lassTopic.asp
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx


This way you wouldn't have to decide whether the object is "too big" or not.
You can let the CLR decide for you! ;)

-D



Angelos Karantzalis said:
Hi, I'm in a situation where I have a Web App that needs to load some xml
info in-memory, and keep it there throughout the lifetime of my
application.

Since the Xml could get large (200K+) and I wouldn't ned to use any
xml-specific operations on it (modify it, or do XPaths, xslt or whatever)
I
de-serialize the xml into an object graph.

My question is:
Can I find out exactly how much memory my object graph occupies ? I want
to
make some comparisons between holding that into memory, and holding an
XmlDocument instead ( because of the Xml-related operations I could use in
case I held the XmlDocument, it might be worth the trade, but I can't
judge
without first knowing the difference in memory consumption :? )

Thanks a lot guys,
Angel
O:]
 
Back
Top