75

I have a .NET service with a normal private working set of about 80 MB. During a recent load test, the process reached 3.5 GB memory usage causing the whole machine to be low on physical memory (3.9 of 4 GB used), and the memory was not released long after the load test was stopped. Using task manager, I took a dump file of the process and opened it in Visual Studio 2010 SP1, and I am able to start debugging on it.

How do I diagnose the memory issue? I have dotTrace Memory 3.x at my disposal, does it support memory profiling on dump files? If not, will the memory profiling features of Visual Studio 2010 Premium help (I currently have Professional)? Can WinDbg help?

UPDATE: The new Visual Studio 2013 Ultimate can now natively diagnose memory issues using dump files. See this blog post for more details.

4

4 に答える 4

128

Install WinDbg. You need to make sure you get the correct version x86 or x64 depending on your dump. Here is a direct link to the download for x86.

On that, you need to ensure you took the correct dump. You can use Task Manager to create the dump file (right click on process -> Create Dump File). If you're on 64bit and your process is x86 use the 32bit version of Task Manager (C:\Windows\SysWOW64\taskmgr.exe) to take the dump file. See my article for more info on taking dump files, eg if you're on XP and need to use windbg to create the dump file.

warning there's a fairly steep learning curve and things might not work exactly as described here so come back with any issues.

I'm assuming you're using .NET4 given you can open the dump in Visual Studio. Here's a very quick guide to help you work with your dmp file:

1) Run WinDbg, set symbols path (File -> Symbol Search Path) to

SRV*c:\symbols*http://msdl.microsoft.com/download/symbols

2) Open Crash dump or drag your .DMP file onto WinDbg.

3)type this into the command window

.loadby sos clr

(FYI, for .NET 2, the command should be .loadby sos mscorwks)

4) then type this

!dumpheap -stat

which lists the type of objects and their count. looks something like this:

enter image description here

You will have to analyze this in the context of your application and see if anything appears unusual.

There is much more to windbg, google is your friend.

于 2012-03-01T15:09:10.067 に答える
33

一般に、管理対象アプリケーションにリークがある場合は、何かが収集されていないことを意味します。一般的な情報源は次のとおりです。

  • イベントハンドラー:サブスクライバーが削除されない場合、パブリッシャーはそれを保持します。

  • 静力学

  • ファイナライザー:ブロックされたファイナライザーは、ファイナライザースレッドが他のファイナライザーを実行できないようにするため、これらのインスタンスが収集されないようにします。

  • 同様に、デッドロックされたスレッドは、保持しているルートを保持します。もちろん、スレッドがデッドロックしている場合は、おそらくいくつかのレベルでアプリケーションに影響を及ぼします。

これをトラブルシューティングするには、管理対象ヒープを検査する必要があります。WinDbg + SOS(またはPSSCOR)を使用すると、これを実行できます。この!dumpheap -statコマンドは、管理対象ヒープ全体をリストします。

ヒープ上で予想される各タイプのインスタンスの数を把握しておく必要があります。奇妙に見えるものを見つけたら、!dumpheap -mt <METHOD TABLE>コマンドを使用して、特定のタイプのすべてのインスタンスを一覧表示できます。

次のステップは、これらのインスタンスのルートを分析することです。ランダムに1つ選び、それを実行し!gcrootます。これにより、その特定のインスタンスがどのようにルート化されているかがわかります。イベントハンドラーと固定されたオブジェクトを探します(通常は静的参照を表します)。そこにファイナライザーキューが表示されている場合は、ファイナライザースレッドが何を行っているかを調べる必要があります。!threadsそのためのand!clrstackコマンドを使用します。

そのインスタンスですべてが正常に見える場合は、別のインスタンスに移動します。それでも何も得られない場合は、戻ってヒープをもう一度確認し、そこから繰り返す必要があります。

リークのその他の原因には、次のものがあります。アンロードされていないアセンブリおよびラージオブジェクトヒープの断片化。SOS / PSSCORは、これらを見つけるのにも役立ちますが、ここでは詳細をスキップします。

もっと知りたいのなら、テスのブログをお勧めします。WinDbg + SOSの使用方法をカバーするビデオもいくつか作成しました(ここここ)。

実行中にプロセスをデバッグするオプションがある場合は、SOSの代わりにPSSCORを使用することをお勧めします。PSSCORは、基本的にSOSソースのプライベートブランチであり、追加のコマンドで拡張されており、既存のSOSコマンドの多くも同様に改善されています。たとえば、PSSCORバージョンの!dumpheapコマンドには非常に便利なデルタ列があり、メモリリークのトラブルシューティングがはるかに簡単になります。

これを使用するには、プロセスを開始し、WinDbgを接続してPSSCORをロードし、を実行する必要があります!dumpheap -stat。次に、プロセスを再度実行して、割り当てを行います。実行を中断し、コマンドを繰り返します。これで、PSSCORは、前回の検査以降に追加/削除されたインスタンスの数を表示します。

于 2012-03-01T16:12:41.517 に答える
6

Since version 2017.2 JetBrains dotMemory supports Windows memory dumps analysis with all its power and fancy GUI.

于 2017-12-04T19:06:22.273 に答える
0

http://msdn.microsoft.com/en-us/library/ee817660.aspx

Microsoft has a guide here. However, it is too tough for beginners.

dotTrace can generate visual memory charts (better than WinDbg), but never use it for dumps.

于 2012-03-01T12:26:20.550 に答える