PLS HELP! - Getting object size

M

MuZZy

Hi,

Is it ever possible to obtain an object's current size in managed memory?
E.g. if i want to know what's the size in bytes occupied by the particular DataSet object right now
(of cource including it's tables, constraints, reations and schemas).

As i posted earlier the project i'm working on is experiencing dramatc memory leaks and i can't seem
to find exactly where the problem is. I suspect that it's the DataSet derived class we are widely
using that is causing that, but as this class is used in tons of other classes and places, i can't
find which objects increase memory.


Thank you,
Andrey
 
N

Nicholas Paldino [.NET/C# MVP]

Andrey,

It's not really easy to determine the size of an object in memory (after
all, an object might have references to other objects, and you have to find
the size of those objects, also, you have to hook into the profiling API, I
believe, to get this kind of information).

Have you used the CLR profiler to take a look at the lifetime of your
objects? It would be much easier, IMO to go that way.
 
M

MuZZy

Nicholas said:
Andrey,

It's not really easy to determine the size of an object in memory (after
all, an object might have references to other objects, and you have to find
the size of those objects, also, you have to hook into the profiling API, I
believe, to get this kind of information).

Have you used the CLR profiler to take a look at the lifetime of your
objects? It would be much easier, IMO to go that way.

Tes,i tried to use CLR Profiler, but it's running really slow under it and sometimes just freezing..
Also, i found that for some reason profiler doesn't show references and objects correctly - in one
case i knew that i have 10 instances of a class which were live but the map showed only two objects.

By the way, does the profiler map's lines show the objects references?

Also, it's weird, i see that my MDI Parent form class has a reference only to the first child form
class, and that child class keeps references to other objects, but if i unreference the child form
class, those objects don't disappear in the profiler map
 
J

Jason Black [MSFT]

I'm not sure if you can get that information directly for a given object,
but the garbage collector class does have a static GC.GetTotalMemory()
method for determing your program's overall memory usage. You can
instrument your app to emit this information around calls where you think
you might be creating problems (e.g. around the creation of a DataSet
derived class, or around the times when data is added/removed from the set,
etc.).
 

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

Top