How to find the memory used by each object in the program?

How to find out about the memory used by each object in the program?

For example: I want to know how much memory (in Kb) this "someclassinstance" object is using ..

someclass someclassinstance = new someclass ();

I see the shared memory used by the application in the task manager ... But is there a way to see a detailed memory usage report for each instance of the object?

Note. I tried the CLR profiler .. but it only shows the shared memory used by strings as far as I know ... It does not display the memory used by each string object.

thanks

+4
source share
5 answers

The CLR profiler is free and can do it. It has a learning curve, but comes with the documentation you need.

+1
source

The .NET Memory Profiler is excellent. He got a 14-day trial and is pretty cheap after that. It allows you to track all the instances that you have, graph them and see how much memory each takes. This gives you a great idea of ​​what exactly is happening in your application.

+2
source

Red Gate Software makes the Ants Profiler, which I believe will provide you with the information you need. It is clearly not free, but there is a 15-day trial version and depending on whether you are lucky enough to have a budget for the software at your work, you can buy it.

+1
source

The allocated memory priority for new someclass rounded to sizeof (someclass); rounding is probably something like sizeof (someclass) + sizeof (void *), rounded to 32.

This will not tell you that, if there is, someclass allocates memory for its members.

The best way to do this might be to replace the global new operator with a shell in which bytes are written. Note that, as indicated above, the requested bytes are smaller than the actually allocated bytes, for accounting and alignment reasons.

This can be done in C ++, I do not know about C #.

0
source

A free, extremely powerful and fairly sophisticated way to do this with Windbg + SOS

This blog post should be enough for you to disconnect.

0
source

All Articles