You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: support/developer/webapps/iis/site-behavior-performance/data-capture-managed-memory-leak.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@ ms.reviewer: khgupta, v-sidong
8
8
9
9
# Data capture for managed memory leaks
10
10
11
-
When you [confirm that the type of memory leak](high-memory-consumption-issues-overview.md#identify-whether-the-memory-leak-is-managed-or-native) is managed memory leaks, collect memory dumps of the process during the high memory usage event. These dumps can help you analyze and diagnose the cause of these leaks.
11
+
If your application is consuming high memory due to [managed memory leaks](high-memory-consumption-issues-overview.md#identify-whether-the-memory-leak-is-managed-or-native),
12
+
collect memory dumps of the process during the high memory usage event. These dumps can help you analyze and diagnose the cause of these leaks.
12
13
13
14
This article outlines the steps to capture memory dumps associated with managed memory leaks, both for consistently reproducible and intermittent cases.
Copy file name to clipboardExpand all lines: support/developer/webapps/iis/site-behavior-performance/high-memory-consumption-issues-overview.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ This troubleshooting guide provides steps to diagnose and resolve high memory co
26
26
Memory leaks generally result in a steady increase in memory usage, leading to crashes or performance degradation:
27
27
28
28
> [!NOTE]
29
-
> High memory usage doesn't always indicate a leak; processes might recover if the allocated memory is freed later. A memoryleak is caused by one or more bugs in the application where allocations are never freed.
29
+
> High memory usage doesn't always indicate a leak; processes might recover if the allocated memory is freed later. A memoryleak is caused by one or more bugs in the application where allocations are never freed.
30
30
31
31
-**32-bit applications**: 32-bit applications might crash and throw an `OutOfMemory` exception when running out of memory, possibly without reporting errors before crashing. They can behave unpredictably if memory allocation failures aren't handled properly in the application code.
32
32
-**64-bit applications**: 64-bit applications rarely fail when trying to allocate virtual memory due to the large address space. However, they can grow to have a very large virtual address space and cause excessive paging of physical memory, which affects the application and other applications that are competing for physical memory.
@@ -35,7 +35,7 @@ Memory leaks generally result in a steady increase in memory usage, leading to c
35
35
| --- | --- | --- |
36
36
| 32-bit applications on 32-bit Windows | 4 GB in total (2 GB in [user mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode), 2 GB in [kernel mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode))|If you use the **/LARGEADDRESSAWARE** flag in your 32-bit applications and the **/3GB** switch in the **boot.ini** file of the operating system during boot time, it makes the user mode memory 3 GB and the kernel mode 1 GB. |
37
37
| 32-bit applications on 64-bit Windows | 4 GB in total (2 GB in [user mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode), 2 GB in [kernel mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)) |If you use the **/LARGEADDRESSAWARE** flag in your 32-bit applications, it makes the user mode memory 4 GB. The kernel doesn't use the 32-bit address space on a 64-bit operating system. It uses only the required space from the 64-bit address space. |
38
-
| 64-bit applications on 64-bit Windows |The theoretical memory limit is 16 exabytes (EB). However, the actual memory limit is determined by the operating system and hardware capabilities. The practical limit on 64-bit Windows 10 is 256 terabytes (TB) (128 TB in user mode, 128 TB in kernel mode).|NA|
38
+
| 64-bit applications on 64-bit Windows |2^64 bytes = 16 Exabyte (EB) (~100 Crore GB). However, Windows10 x 64 supports 48 bits virtual address: 2^48 bytes = 256 TB (128 TB in [user mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode), 128 TB in [kernel mode](/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)). |NA|
39
39
|64-bit applications on 32-bit Windows |Invalid scenario |NA|
40
40
41
41
## Identify high memory usage
@@ -87,25 +87,28 @@ Once you've confirmed the type of memory leak, the next step is to use tools to
87
87
88
88
## .NET Core applications
89
89
90
-
If the application in question is .NET Core and hosted on IISin in-processmode, use the data collection steps in [Data capture for managed memory leaks](data-capture-managed-memory-leak.md) and [Troubleshoot native memory leak in an IIS 7.x application pool](troubleshoot-native-memory-leak-iis-7x-application-pool.md). However, if the application is hosted on IIS inout-of-processmode, modify the actions to investigate the dotnet process (**dotnet.exe**unless otherwise specified) instead of**w3wp.exe**. The same thing appliesto self-hosted.NET Core applications.
90
+
If the application in question is .NET Core and hosted on IISin in-processmode, use the data collection steps in [Data capture for managed memory leaks](data-capture-managed-memory-leak.md) and [Troubleshoot native memory leak in an IIS 7.x application pool](troubleshoot-native-memory-leak-iis-7x-application-pool.md). However, if the application is hosted on IIS inout-of-processmode, modify the actions to investigate the dotnet process (**dotnet.exe**unless otherwise specified) instead of**w3wp.exe**. The same thing appliesto self-hosted.NET Core applications.
91
91
92
92
## Troubleshooting example
93
93
94
94
Assume you have an application hosted on an IIS server and you experience high memory usage (the memory spikes up to around 7 GB by doing a stress test) when accessing a specific URL, follow these steps to diagnose the issue:
95
95
96
96
1. Check Performance Monitor by following the steps in [Identify whether the memory leak is managed or native](#identify-whether-the-memory-leak-is-managed-or-native). If you notice **Private Bytes** and **# Bytes in all Heaps** remain constant, it's a managed memory leak.
97
97
1. Collect dump files by following the steps described in [Using DebugDiag](data-capture-managed-memory-leak.md#method-2-using-debugdiag).
98
-
1. Open the dump files in [WinDbg](/windows-hardware/drivers/debugger/) and run the following commands based on your scenario.
98
+
1. Open the dump files in [WinDbg](/windows-hardware/drivers/debugger/). For high memory scenarios, you can use the following commands:
99
99
100
100
|Command|Usage|
101
101
|---|---|
102
-
|`!dumpheap -stat`|This command shows you all objects on the managed heap and their statistics. You can customize the output using the different switches of`!dumpheap` to focus on specific types of objects, sizes, or states, making it easier to analyze the managed heap and identify issues such as memory leaks. |
102
+
|`!dumpheap -stat`|This command shows you all objects on the managed heap and their statistics. You can customize the output using the different switches of`!dumpheap` to focus on specific types of objects, sizes, or states, making it easier to analyze the managed heap and identify issues such as memory leaks. |
103
103
|`!eeheap -gc`|This command can be used to get the managed heap size. |
104
104
|`!threads`|This command helps check for any finalizer threads that display all managed threads. |
105
105
|`!finalizequeue`|This command is used to display all objects in the finalize queue. |
106
106
107
107
1. After running `!dumpheap -stat`, you see that `system.char[]`, `system.Text.Stringbuilder`, and `BuggyBits.Models.Link` consume the most objects on the heap, with counts of 322,547, 322,408, and 320,031.
108
108
109
+
> [!NOTE]
110
+
> `BuggyBits` is the sample application name used in this example. You might see your application name or other process name which might be consuming high objects.
@@ -153,7 +156,7 @@ Assume you have an application hosted on an IIS server and you experience high m
153
156
```
154
157
155
158
1. Dump the statistics for various sizes of `char[]` to find out if there's a pattern (this is a trial-and-error process, so you have to try different sizes to determine where the bulk of the strings are).
156
-
1. Run the command `!dumpheap -mt 7ff93d333058` to list all objects on the managed heap that have the specified method table (MT) address `7ff93d333058` (`System.Char[]`).
159
+
1. Run the command `!dumpheap -mt 7ff93d333058` to list all objects on the managed heap that have the specified method table (MT) address `7ff93d333058` for `System.Char[]`.
157
160
158
161
```output
159
162
Address MT Size
@@ -228,7 +231,9 @@ Assume you have an application hosted on an IIS server and you experience high m
228
231
Fields:
229
232
```
230
233
231
-
1. Run `gcroot` on some of those addresses, and you see a finalizer queue:
234
+
1. Now, you need to know why they're not collected.
235
+
236
+
If you run `gcroot` on some of those addresses, and you see a finalizer queue:
232
237
233
238
```output
234
239
0:000> !gcroot 017e9a469e08
@@ -239,7 +244,9 @@ Assume you have an application hosted on an IIS server and you experience high m
239
244
-> 017e9a469e08 System.Char[]
240
245
```
241
246
242
-
1. Run `!threads` to list all threads and show their states. You see thread 42 has a finalizer:
247
+
1. Check the finalizer thread to see what it's doing.
248
+
249
+
Run `!threads` to list all threads and show their states. You see thread 42 has a finalizer:
243
250
244
251
```output
245
252
0:000> !threads
@@ -335,6 +342,9 @@ Assume you have an application hosted on an IIS server and you experience high m
335
342
336
343
1. Check the following code snippet in the **Link.cs** file, and you'll see that there's an explicit call to `Thread.Sleep`, which is causing high memory usage.
337
344
345
+
> [!NOTE]
346
+
> As mentioned earlier in the article, `BuggyBits` and the following code snippet are specific to the sample application used to create this example.Check your application code if you come across a similar scenario and found a specific method in your application that's causing high memory issue based on the dump analysis.
347
+
338
348
```C#
339
349
// BuggyBits.Models.Link
340
350
// Flags = reuse slot, hide by signature
@@ -352,8 +362,6 @@ Assume you have an application hosted on an IIS server and you experience high m
352
362
}
353
363
```
354
364
355
-
The preceding step-by-step approach can help you diagnose and address high memory usage issues.
356
-
357
365
## More information
358
366
359
367
-[Use Performance Monitor to find a user-mode memory leak](/windows-hardware/drivers/debugger/using-performance-monitor-to-find-a-user-mode-memory-leak)
0 commit comments