Skip to content

Commit c0e46a9

Browse files
authored
update as per Khushboo
1 parent 782fc6e commit c0e46a9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

support/developer/webapps/iis/site-behavior-performance/data-capture-managed-memory-leak.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ ms.reviewer: khgupta, v-sidong
88

99
# Data capture for managed memory leaks
1010

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.
1213

1314
This article outlines the steps to capture memory dumps associated with managed memory leaks, both for consistently reproducible and intermittent cases.
1415

support/developer/webapps/iis/site-behavior-performance/high-memory-consumption-issues-overview.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This troubleshooting guide provides steps to diagnose and resolve high memory co
2626
Memory leaks generally result in a steady increase in memory usage, leading to crashes or performance degradation:
2727

2828
> [!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 memory leak is caused by one or more bugs in the application where allocations are never freed.
3030
3131
- **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.
3232
- **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
3535
| --- | --- | --- |
3636
| 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. |
3737
| 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|
3939
|64-bit applications on 32-bit Windows |Invalid scenario |NA|
4040

4141
## 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
8787

8888
## .NET Core applications
8989

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 IIS in in-process mode, 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 in out-of-process mode, modify the actions to investigate the dotnet process (**dotnet.exe** unless otherwise specified) instead of **w3wp.exe**. The same thing applies to self-hosted .NET Core applications.
9191

9292
## Troubleshooting example
9393

9494
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:
9595

9696
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.
9797
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:
9999

100100
|Command|Usage|
101101
|---|---|
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. |
103103
|`!eeheap -gc` |This command can be used to get the managed heap size. |
104104
|`!threads` |This command helps check for any finalizer threads that display all managed threads. |
105105
|`!finalizequeue` |This command is used to display all objects in the finalize queue. |
106106

107107
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.
108108

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.
111+
109112
```output
110113
7ff93da4a520 601 1,00,968 Microsoft.AspNetCore.Mvc.TagHelpers.ScriptTagHelper
111114
7ff93dbbe068 2,576 1,03,040 Microsoft.AspNetCore.Mvc.ViewFeatures.TemplateInfo
@@ -153,7 +156,7 @@ Assume you have an application hosted on an IIS server and you experience high m
153156
```
154157
155158
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[]`.
157160
158161
```output
159162
Address MT Size
@@ -228,7 +231,9 @@ Assume you have an application hosted on an IIS server and you experience high m
228231
Fields:
229232
```
230233

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:
232237

233238
```output
234239
0:000> !gcroot 017e9a469e08
@@ -239,7 +244,9 @@ Assume you have an application hosted on an IIS server and you experience high m
239244
-> 017e9a469e08 System.Char[]
240245
```
241246

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:
243250

244251
```output
245252
0:000> !threads
@@ -335,6 +342,9 @@ Assume you have an application hosted on an IIS server and you experience high m
335342
336343
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.
337344
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+
338348
```C#
339349
// BuggyBits.Models.Link
340350
// 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
352362
}
353363
```
354364

355-
The preceding step-by-step approach can help you diagnose and address high memory usage issues.
356-
357365
## More information
358366

359367
- [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

Comments
 (0)