パフォーマンス モニター (PerfMon) を使用してユーザー モードのメモリ リークを見つける

ユーザー モードのメモリ リークがあると思われる場合は、Windows パフォーマンス モニター (PerfMon) を使用して、個々のプロセスのメモリ使用量を測定できます。 このツールは、リークの原因となっている特定のプロセスを特定するのに役立ちます。

Open Performance Monitor from Windows Search. Enter perfmon (or Performance Monitor), then right-click the tool and select Run as administrator.

データ カウンターを追加する

データの変更を監視できるように、メインのパフォーマンス モニター グラフにプロセス データ カウンターを追加します。 Under Monitoring Tools, right-click Performance Monitor and select Properties. In the Properties dialog >Data tab, add the following counters:

  • Process>Private Bytes> (for each process to examine): Set the total amount of memory allocated for the specific process, not including memory shared with other processes.

  • Process>Virtual Bytes> (for each process to examine): Set the current size of the virtual address space for the specific process.

十分なアクティビティをキャプチャする期間を設定する

時間の経過に伴うデータ リークのグラフをキャプチャできるように、一般的な時間設定を調整します。 In the Properties dialog >General tab, configure the following values:

  • Sample every: Set the time to 600 seconds, which measures the value every 10 minutes.

  • Duration: Set the time to capture enough activity. For example, to monitor the data over 24 hours, set the value to 86400 (60 x 60 x 24 = 86,400).

Tip

後で確認するために、グラフ データをファイルに記録します。

アプリケーションを起動し、ユーザー モード データを監視する

カウンターと時刻の設定を構成したら、リークを確認するアプリケーションまたはテスト プログラムを起動します。 プログラムがしばらくの間、乱れのない実行を許可します。

Important

プログラムを実行している間は、ターゲット コンピューターを使用してリークをチェックしないでください。 通常、リークはゆっくりと発生します。 データ リークが検出可能なレベルに蓄積されるまでに数時間かかることがあります。

パフォーマンス モニター カウンターを確認します。 監視を開始すると、カウンター値が急速に変化します。 メモリ プールの値が安定した状態に達するまでに時間がかかる場合があります。

  • Private Bytes: Some memory leaks appear in the data file in the form of an increase in private bytes allocated.

  • Virtual Bytes: Some memory leaks appear as an increase in the virtual address space.

リークのある特定のルーチンを検索する

メモリリークしているプロセスを特定したら、ユーザー モード ダンプ ヒープ (UMDH) ユーティリティを使用して、メモリの問題のある特定のルーチンを特定します。 詳細については、「 UMDH を使用してユーザー モードのメモリ リークを見つける」を参照してください。