Analyzing memory dump to find leak

2019-02-24 06:12发布

问题:

We have a c# .NET application that has a memory leak in it. I used procdump to get a memory dump from a running instance of the application from a production machine. The production machine is running 32 bit Windows XP, and .NET 4.0.

The exe config is set to .net 4.0

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />

When I pull the dump to my dev box, windows 8.1 64bit, and open it with VS 2013 the dump is initially opened fine. However, when I click the Debug Managed Memory action I get the following error message:

Memory analysis is not supported for the CLR version used in this process.

I'm new to troubleshooting memory leaks in Windows and managed memory environments, and know next to nothing about the tools involved. I did a google search for the error I get, and didn't find anything. Any help is appreciated. I apologize if I am missing something obvious - Junior Dev here :-)

回答1:

I don't know if procdump can be used to find a memory leak in .NET. One effective way I tried is: using Windbg and SOS. There are two posts explains how to use Windbg+ SOS to track .NET memory leaks:

  1. Where's your leak at? [Using WinDbg, SOS, and GCRoot to diagnose a .NET memory leak]
  2. Debugging managed code memory leak with memory dump using windbg

If you don't like Windbg, the tool DebugDiag is also very effective tool in tracking down memory leaks.



回答2:

See this link, it only works on process running under .Net 4.5

Before I begin, there are a few things to note about the "Debug Managed Memory" feature discussed in this post:

  1. The option will only be available from the dump summary page in the Ultimate version of Visual Studio 2013. If you are using Premium or Professional you will not see the option
  2. The process the dump file was collected against must have been running on .NET 4.5 or higher. If the dump was collected on 3.5 or previous the option will not appear, if it was collected on 4.0 it will fail to launch with an error message.


回答3:

Starting with Windows 7 /Server 2008 R2 there is a way to create a clone of a process and create a dump of this clone so that the process you care about doesn't need to be suspended. Use procdump -r to use this feature when capturing a dump.

You can also use capture a ETW trace and analyze the data with PerfView.

https://superuser.com/questions/846079/how-can-i-create-a-memory-dump-of-a-production-system-without-affecting-performa/846156#846156