Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the memory snapshot in Visual Studio

I use Visual Studio to take memory snapshot of my application.

I have some questions about understanding the data I got. I after I capture the memory snapshot, I filter out one of my class, say MyClassPanel. I only use MyClassPanel in my xmal files.

  1. why ‘Paths to Root’ for MyClassPanel are all ‘MyClassPanel [RefCount Handle, Count:1]’? (i.e. same name but with a string [RefCount Handle at the end] and a different Count value) what does this mean? In other class, I filter, I see the 'Paths to Root' are different class names.

  2. I have 24 MyClassPanel (from the count in top table). And in the ‘Reference Count’ column in the bottom table, when I add them up, they are 24.

Is that always the case? I think ‘Count’ and ‘Reference Count’ means different things. In this case, they add up. Does this make sense?

enter image description here

like image 610
n179911 Avatar asked Jun 05 '15 18:06

n179911


People also ask

How do I find memory leaks in Visual Studio?

To find memory leaks and inefficient memory usage, you can use tools such as the debugger-integrated Memory Usage diagnostic tool or tools in the Performance Profiler such as the . NET Object Allocation tool and the post-mortem Memory Usage tool.

How do you analyze memory usage?

Check Computer Memory Usage EasilyTo open up Resource Monitor, press Windows Key + R and type resmon into the search box. Resource Monitor will tell you exactly how much RAM is being used, what is using it, and allow you to sort the list of apps using it by several different categories.

How do you take a memory snapshot?

Take a memory snapshotFrom the main menu, select View | Tool Windows | Profiler, right-click a running process and select Capture Memory Snapshot. When the snapshot is captured, it opens for analysis right away.


2 Answers

  1. The Paths to Root view shows the references to this type keeping it from being garbage collected. Since your class is a Xaml page, the reference which keeps the class alive is a CLR handler for the Xaml page. These show up as RefCount Handle.

  2. Count and reference count are indeed not the same. Count is the number of instances, reference count the number of references. Because each instance in your case only has one reference, it makes sense they add up.

For more info:

  • https://devblogs.microsoft.com/devops/using-visual-studio-2013-to-diagnose-net-memory-issues-in-production/
  • https://learn.microsoft.com/visualstudio/profiling/analyze-memory-usage
  • https://learn.microsoft.com/visualstudio/profiling/memory-usage
like image 120
Rolf Huisman Avatar answered Oct 25 '22 15:10

Rolf Huisman


I am not a big fan of Visual Studio Snapshot analyzer. There are quite a few complications available if finalization is not properly executed before taking the snapshot. I am not sure how Visual Studio handles that. However, the snapshot you have provided doesn't make much sense for me either.

I would suggest you to download the ANTS memory profiler and investigate this. It comes with a reasonable trial period. By using that, you will be able to see all references to each instance by using it's 'Retention Graph'. It will specifically show you which instances keeps the reference to your objects and also it will show you which objects have implemented Dispose but hasn't call. I guess, it will provide more support to find the root cause for this issue.

Have a look at below pages walkthrough

http://www.red-gate.com/products/dotnet-development/ants-memory-profiler/walkthrough http://www.red-gate.com/products/dotnet-development/ants-memory-profiler/

like image 31
CharithJ Avatar answered Oct 25 '22 14:10

CharithJ