Skip to content

Commit 809b2bb

Browse files
committed
AB#6575 troubleshoot-application-service-memory-leaks.md
1 parent c672ba8 commit 809b2bb

11 files changed

Lines changed: 203 additions & 0 deletions
79.5 KB
Loading
60.8 KB
Loading
71 KB
Loading
125 KB
Loading
46.6 KB
Loading
294 KB
Loading
272 KB
Loading
63.4 KB
Loading
152 KB
Loading
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
title: Aplication or service memory leaks troubleshooting guidance
3+
description: Provides guidance on how to troubleshoot application or service memory leaks.
4+
ms.date: 07/22/2025
5+
manager: dcscontentpm
6+
audience: itpro
7+
ms.topic: troubleshooting
8+
ms.reviewer: kaushika, warrenw, v-lianna
9+
ms.custom:
10+
- sap:system performance\app,process,service performance (slow,unresponsive)
11+
- pcy:WinComm Performance
12+
---
13+
# Application or service memory leaks troubleshooting guidance
14+
15+
This article provides guidance to troubleshoot applications or services with memory leak behaviors and how to proceed.
16+
17+
_Applies to:_   All supported versions of Windows Server and Windows Client
18+
19+
You see Event ID 2004 repeatedly in the system log. As the event source mentions, there's a resource exhaustion in the system on the virtual memory space. The description lists the system's top memory consumers at that time.
20+
21+
Apart from this event, you also notice high memory consumption by checking live or historical data from monitoring tools, or by using the Windows Task Manager.
22+
23+
The following troubleshooting process is helpful for both scenarios where first-party and third-party processes might be leaking memory. For first-party processes, you can use the public symbol store available. However, if you can't see the actual function in a third-party process, you can engage the vendor for further checking. Even if the function doesn't show, the allocation stack should indicate a third-party module.
24+
25+
A few SysInternals tools and Windows Performance Toolkit will be used.
26+
27+
## Before you begin
28+
29+
You might see the following examples in the system event log and Task Manager.
30+
31+
```output
32+
Log Name: System
33+
Source: Microsoft-Windows-Resource-Exhaustion-Detector
34+
Date: <DateTime>
35+
Event ID: 2004
36+
Task Category: Resource Exhaustion Diagnosis Events
37+
Level: Warning
38+
Keywords: Events related to exhaustion of system commit limit (virtual memory).
39+
User: SYSTEM
40+
Computer: WIN-LAB
41+
Description:
42+
Windows successfully diagnosed a low virtual memory condition. The following programs consumed the most virtual memory:wpa.exe (9844) consumed 13714722816 bytes, msedgewebview2.exe (112572) consumed 3037757440 bytes, and EngHost.exe (37280) consumed 2619834368 bytes.
43+
```
44+
45+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/task-manager-testlimit.png" alt-text="Screenshot of Task Manager showing the Testlimit process with high memory consumption.":::
46+
47+
The memory shown in the default list of columns isn't the one that should be focused on, since it represents the memory privately used by the process but backed by physical memory (working set). You need to verify virtual memory that is used by the operating system for its operation regardless of the way the virtual memory is backed (RAM or pagefile). In this case, you need to verify **Commit size**.
48+
49+
Here're some examples:
50+
51+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/task-manager-testlimit-commit-size.png" alt-text="Screenshot of Task Manager showing the Testlimit process with high commit size.":::
52+
53+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/task-manager-virtmem-commit-size.png" alt-text="Screenshot of Task Manager showing the VirtMemTest32 process with high commit size.":::
54+
55+
You can use [VMMap](/sysinternals/downloads/vmmap) and [Windows Performance Toolkit](/windows-hardware/test/wpt) for the troubleshooting.
56+
57+
VMMap is used to determine the type of memory leaks. The Windows Performance Toolkit includes the Windows Performance Recorder (WPR) tool and the Windows Performance Analyzer (WPA) tool, which are used to collect and analyze data.
58+
59+
## Gather data
60+
61+
During this stage, if the memory usage is growing over time and not releasing, which indicates a leak pattern. The increase doesn't need to be a straight line to fall into this pattern, what matters is that the memory usage keeps on increasing over time.
62+
63+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/increase-leak-pattern.png" alt-text="Screenshot of the memory usage with an increase pattern.":::
64+
65+
At this point, with a leak pattern, you need to determine the leaking memory type. Open VMMap and select the process that has been identified as the leaking memory.
66+
67+
### Determining the memory type
68+
69+
When virtual allocation memory is leaked, it's represented in VMMap as **Private Data**:
70+
71+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/vmmap-private-data.png" alt-text="Screenshot of the virtual allocation memory leaks represented as Private Data in VMMap.":::
72+
73+
If you have a memory dump of the process, you can run the following command to see the memory layout. Virtual allocation shows as `<unknown>`:
74+
75+
```console
76+
0:000> !address -summary
77+
78+
--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
79+
Free 58 0`85c87000 ( 2.090 GB) 52.26%
80+
<unknown> 56 0`7866f000 ( 1.881 GB) 98.52% 47.03%
81+
Image 116 0`016de000 ( 22.867 MB) 1.17% 0.56%
82+
Stack32 9 0`00240000 ( 2.250 MB) 0.12% 0.05%
83+
Other 6 0`001aa000 ( 1.664 MB) 0.09% 0.04%
84+
Heap32 8 0`0012b000 ( 1.168 MB) 0.06% 0.03%
85+
Stack64 9 0`000c0000 ( 768.000 kB) 0.04% 0.02%
86+
Heap64 4 0`00039000 ( 228.000 kB) 0.01% 0.01%
87+
TEB64 3 0`00006000 ( 24.000 kB) 0.00% 0.00%
88+
TEB32 3 0`00006000 ( 24.000 kB) 0.00% 0.00%
89+
PEB64 1 0`00001000 ( 4.000 kB) 0.00% 0.00%
90+
PEB32 1 0`00001000 ( 4.000 kB) 0.00% 0.00%
91+
```
92+
93+
When heap allocation memory is leaked, it's represented with **Heap**:
94+
95+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/virtmem-heap-allocation.png" alt-text="Screenshot of the VirMemTest32 process with the heap allocation memory leaks represented as Heap in VMMap.":::
96+
97+
If you have a memory dump of the process, you can run the following command to see the memory layout. Heap allocation shows as `Heap`:
98+
99+
```console
100+
0:000> !address -summary
101+
102+
--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
103+
Heap32 67 0`709f3000 ( 1.760 GB) 91.47% 87.99%
104+
Free 115 0`04e03000 ( 78.012 MB) 3.81%
105+
<unknown> 59 0`0470c000 ( 71.047 MB) 3.61% 3.47%
106+
Image 225 0`02e8f000 ( 46.559 MB) 2.36% 2.27%
107+
Other 37 0`021af000 ( 33.684 MB) 1.71% 1.64%
108+
Stack32 39 0`00d00000 ( 13.000 MB) 0.66% 0.63%
109+
Stack64 39 0`00340000 ( 3.250 MB) 0.16% 0.16%
110+
Heap64 4 0`00039000 ( 228.000 kB) 0.01% 0.01%
111+
TEB64 13 0`0001a000 ( 104.000 kB) 0.01% 0.00%
112+
TEB32 13 0`0001a000 ( 104.000 kB) 0.01% 0.00%
113+
Other32 1 0`00001000 ( 4.000 kB) 0.00% 0.00%
114+
PEB64 1 0`00001000 ( 4.000 kB) 0.00% 0.00%
115+
PEB32 1 0`00001000 ( 4.000 kB) 0.00% 0.00%
116+
```
117+
118+
### Collect trace data for virtual allocation memory
119+
120+
With the way to identify the leaking memory, the next step is to collect reproducible data to determine the driver responsible for the leaking allocations.
121+
122+
Use the following command to collect data when the process shows the behavior. Note that **WPR.exe** is included natively on operating systems after Windows 10 or Windows Server 2016.
123+
124+
Run the following command from a command prompt as an administrator:
125+
126+
```console
127+
C:\>wpr -start VirtualAllocation
128+
```
129+
130+
Allow the process to run for some time. You can monitor the growth of memory consumption with Task Manager (**Commit size**).
131+
132+
Since it only collects virtual allocation data, the trace file won't grow that big, so you can let it run for several minutes. Once you see enough leaked memory, stop the trace by using the following command:
133+
134+
```console
135+
C:\>wpr -stop virtalloc.etl
136+
```
137+
138+
### Collect trace data for heap allocation memory
139+
140+
Like virtual allocation, you can also leverage WPR for heap tracing.
141+
142+
However, a registry modification is required to enable the heap tracing. You can manually modify the registry or run the following command to enable heap tracing for the target process (for example, **VirtMemTest32.exe**).
143+
144+
Run the following command from a command prompt as an administrator:
145+
146+
```console
147+
C:\>wpr -heaptracingconfig VirtMemTest32.exe enable
148+
```
149+
150+
> [!NOTE]
151+
> If the process is running when you run the command, restart the process for the setting to be enabled.
152+
153+
Heap tracing was successfully enabled for process **VirtMemTest64.exe**.
154+
155+
The result is:
156+
157+
Registry key: `Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image File Execution Options\VirtMemTest32.exe`
158+
Value name: `Tracing Flags`
159+
Value type: `REG_DWORD`
160+
Value data: `0x00000001 (1)`
161+
162+
You can delete the registry key after the troubleshooting or set the value to `0`.
163+
164+
Use the following command to collect data when the process shows the behavior. Note that WPR.exe is included natively on operating systems after Windows 10 or Windows Server 2016.
165+
166+
Run the following command from a command prompt as an administrator:
167+
168+
```console
169+
C:\>wpr -start Heap
170+
```
171+
172+
Allow the process to run for some time. You can monitor the growth of memory consumption with Task Manager (**Commit size**).
173+
174+
Since it only collects heap data, the trace file won't grow that big, so you can let it run for several minutes. Once you see enough leaked memory, stop the trace by using the following command:
175+
176+
```console
177+
C:\>wpr -stop Heap.etl
178+
```
179+
180+
## Analyze data
181+
182+
Use **WPA.exe** to open the trace. WPA can be downloaded via the Assessment and Deployment Kit (ADK) package for the Windows Performance Toolkit.
183+
184+
Open WPA and set up the symbol path. In the menu, select **Trace** > **Configure Symbol Paths**. Configure symbols by adding the public symbol path as **srv*C:\LocalPubSymbols*https://msdl.microsoft.com/download/symbols**, so you can load symbols (in the menu, select **Trace** > **Load Symbols**) before checking the trace.
185+
186+
### Analyze trace data for virtual allocation memory
187+
188+
Replicate the following view by replacing the process with the one you've identified as relevant. Ensure that the **Commit Stack** column is on the left of the gold/yellow line. Drill down by expanding the stack, and you'll see the function that shows the allocation of virtual memory. The driver listed before (up) the function is the one calling to that operation.
189+
190+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/trace-data-virtual-allocation.png" alt-text="Screenshot of the analysis trace data for virtual allocation memory.":::
191+
192+
### Analyze trace data for heap allocation memory
193+
194+
Replicate the following view by replacing the process with the one you've already identified as relevant. Ensure that the **Handle** and **Stack** columns are on the left of the gold/yellow line. Drill down by expanding the stack, and you'll see the function that shows the allocation of heap memory. The driver listed before (up) the function is the one calling to that operation.
195+
196+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/trace-data-heap-allocation.png" alt-text="Screenshot of the analysis of the trace data for heap allocation memory.":::
197+
198+
:::image type="content" source="./media/troubleshoot-application-service-memory-leaks/heap-allocation-function-driver.png" alt-text="Screenshot of the analysis of the trace data for heap allocation memory with the drive listed.":::
199+
200+
> [!NOTE]
201+
> If you don't see the heap allocation graph, it's because the registry key isn't set correctly. Review the steps.

0 commit comments

Comments
 (0)