user555265
user555265

Reputation: 493

Any way in C# / .NET app to get breakdown of memory allocated to each type in memory?

I have an app which consumes a lot of real time data, and because it's doing so much it's quite slow under the VS 2010 and this causes it to fail in various ways.

So I was wondering if there's any way other than this profiler that I can find out how much memory in bytes say is allocated to each type in memory and dump this out periodically?

It's quite a large application so adding my own counters isn't really feasible...

Upvotes: 0

Views: 239

Answers (3)

Tigran
Tigran

Reputation: 62248

I would suggest like for getting a general information massively use Process Explorer. One time you gfigure out you need to understand the stuff deeper (what kind of objects are on heap, for example) , the best tool I used for profiling is JetBrains Memory and Performance profiler. This one is payed only.

If you need only performance profiler, there is really good free option Equatec Performance profiler

Good luck.

Upvotes: 0

Rob Levine
Rob Levine

Reputation: 41298

There is no easy general purpose way of saying GetBytesUsedForInstance(object), but it depends what you need the data for (unless all your types are value types, in which case it should be relatively simple).

We have an in memory cache for part of our application. We care most about relative amounts of memory used - ie the total cache size is twice what it was yesterday. For this, we serialize our object graphs to a stream and take the stream length (and then discard the stream). This is not an accurate measurement of "how much memory a type uses up" per se, but is useful for these relative comparisons.

Other than that - I think you are stuck using a profiler. I can highly recommend SciTech Memory Profiler - I use it a lot. It integrates well into Visual Studio, is fast (the latest version is anyway), and gives tremendously useful detail.

Upvotes: 0

Oded
Oded

Reputation: 498904

You need to use a memory profiler.

There are many around, some free and some commercial.

Also see What Are Some Good .NET Profilers?

Upvotes: 2

Related Questions