471,338 Members | 1,196 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

how to check the memory usage of an object at runtime?

Bob
I'm trying to decide on what data types to put into my caching object (a
class with a static instance of Hashtable). I'm facing the choice of either
putting the string values or SqlParameter objects into the Hashtable.
There'll be a couple of hundred of these values. If the SqlParameter
objects don't eat up too much memory comparing to the strings, I'd very much
like to go with the SqlParameters. How can I check the memory usage of my
static class (or rather the static instance Hashtable) at runtime when it's
loaded with the data? I tried the SciTech .NET Memory Profiler but not sure
what I was looking at.

Thanks a lot
Bob
Jul 22 '05 #1
8 1824
Bob <bo*******@yahoo.com> wrote:
I'm trying to decide on what data types to put into my caching object (a
class with a static instance of Hashtable). I'm facing the choice of either
putting the string values or SqlParameter objects into the Hashtable.
There'll be a couple of hundred of these values. If the SqlParameter
objects don't eat up too much memory comparing to the strings, I'd very much
like to go with the SqlParameters. How can I check the memory usage of my
static class (or rather the static instance Hashtable) at runtime when it's
loaded with the data? I tried the SciTech .NET Memory Profiler but not sure
what I was looking at.


I don't know the details of SqlParameter, but I very much doubt that
having a couple of hundred of them would make any significant
difference.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 22 '05 #2
WJ
You may want to use the Size of the class to determine the amt. of ram your
object use.

John
Jul 22 '05 #3

"WJ" <Jo*******@HotMail.Com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
You may want to use the Size of the class to determine the amt. of ram
your object use.

John


And how do you think you can get at the size of the class at run-time?

Willy.
Jul 22 '05 #4
Using profiler.

HTH
Alex

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"WJ" <Jo*******@HotMail.Com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
You may want to use the Size of the class to determine the amt. of ram
your object use.

John


And how do you think you can get at the size of the class at run-time?

Willy.

Jul 22 '05 #5
This is not what I call at run-time! You can't call profiling API's from
managed code, you can only attach a profiler to a running managed process.

Willy.

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Using profiler.

HTH
Alex

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"WJ" <Jo*******@HotMail.Com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
> You may want to use the Size of the class to determine the amt. of ram
> your object use.
>
> John
>


And how do you think you can get at the size of the class at run-time?

Willy.


Jul 22 '05 #6
Somehow I can't agree with "can't call". But this is not the issue, right?
If you attach before object is created and then check heap and allocations
after you create and use object, doesn't this give you the required
information?
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
This is not what I call at run-time! You can't call profiling API's from
managed code, you can only attach a profiler to a running managed process.

Willy.

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Using profiler.

HTH
Alex

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"WJ" <Jo*******@HotMail.Com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
> You may want to use the Size of the class to determine the amt. of ram > your object use.
>
> John
>

And how do you think you can get at the size of the class at run-time?

Willy.



Jul 22 '05 #7
Hi Bob,

there is posibility to check object size at runtime by simply using SOS
debugger. Of course, you can use it from IDE or using "Debugging Tools for
Windows" (ADPPlus).
In both cases you should load SOS debugger (.load sos.dll) and execute
commands like
!dumpheap -type <your class>
pick memory address of that class and get
!objsize <address>
You will get your values.

There is an great article on similar topic at
http://www.csharphelp.com/archives4/archive622.html to start with this.

Of course you should take a look about SOS debugger at Microsoft site.

Best regards,
Dejan Lukovic

"Bob" <bo*******@yahoo.com> escribió en el mensaje
news:#a*************@TK2MSFTNGP15.phx.gbl...
I'm trying to decide on what data types to put into my caching object (a
class with a static instance of Hashtable). I'm facing the choice of either putting the string values or SqlParameter objects into the Hashtable.
There'll be a couple of hundred of these values. If the SqlParameter
objects don't eat up too much memory comparing to the strings, I'd very much like to go with the SqlParameters. How can I check the memory usage of my
static class (or rather the static instance Hashtable) at runtime when it's loaded with the data? I tried the SciTech .NET Memory Profiler but not sure what I was looking at.

Thanks a lot
Bob

Jul 22 '05 #8
Inline

Willy.

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Somehow I can't agree with "can't call". But this is not the issue, right?
If you attach before object is created and then check heap and allocations
after you create and use object, doesn't this give you the required
information?


Sure, but this is what the OP did with the SciTec profiler, and this didn't
seem to fit the bill.
<snip
I tried the SciTech .NET Memory Profiler but not sure
what I was looking at.
/snip>

I guess what the OP wants is to check the object size from within his code.
Note that a profiler only gives you the size of your individual objects not
the size of the object graphs, that means if the object is a container, it
only gives you the (actual) size of the container NOT including the
contained objects. So to get the real object size you have to walk the graph
and add the sizes of the sub-objects to the size of the container, which is
not a trivial task. The final result is the total size of an object graph
that might change over time depending on the size of the subobjects (strings
f.i), so in fact it only gives you a raw estimate, something that's not
worth the trouble IMO.

Willy.



Jul 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by lebo | last post: by
9 posts views Thread by Mike P | last post: by
7 posts views Thread by George Gre | last post: by
20 posts views Thread by Philip Carnstam | last post: by
8 posts views Thread by Afanasiy | last post: by
3 posts views Thread by Gregor Wind | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.