E
E
Ethiopian2015-06-11 10:04:37
.NET
Ethiopian, 2015-06-11 10:04:37

How to find out the number of instances and memory consumption in .NET?

Greetings,
the problem is this: I have a C# client-server application whose server side sometimes leaks memory. Now we are trying to write something like a built-in profiler that could send statistics on memory consumption to the client in real time from the installed server.
The question is:
Is it possible in .NET to find out the classes that consume the most memory and the number of their instances directly from the code, without resorting to third-party profilers like ANTS?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Lastochkin, 2015-06-11
@lasalas

The problem is that scanning objects via the Debugging API requires the application to be "frozen" for the duration of the scan, so it cannot scan itself, so an external debugger (profiler) is needed anyway.
In my experience, static objects and event subscriptions are usually the source of leaks.
I recommend dotTrace , it has incl. and a remote profiler.
Also: "freeze" can last quite a long time, which can be critical when used on a "combat" server.

V
Vitaly Pukhov, 2015-06-11
@Neuroware

the Community version has a built-in profiler, it gives a lot of information

M
MrDywar Pichugin, 2015-06-11
@Dywar

The word "instances" is not very clear, it seems that these are instances of objects.
You can get memory through the Windows "System Monitor" counters (you can even read it remotely, they always work and practically do not load, select a process and look at GC_time, GEN_1,2,3 etc., there are a lot of counters), or subscribe to ETW in your application if .NET 4.5 (it's easier on it) and write events from internal Windows components (CLR, Kernel) to the log.
Take dumps through sysinternals suite software, or task manager, or use PerfView.
One of these days I will make an article "notes 2.0", everything is more detailed there with JIT-from :)
UPD: we shoot 2 dumps at different times, find new objects in the second (they will be if there is a leak), find who is holding them (1 command in Windbg) .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question