Light Freshness Edit: ASP.NET - Performace#37106
Light Freshness Edit: ASP.NET - Performace#37106GitHubber17 wants to merge 4 commits intodotnet:mainfrom
Conversation
|
@tdykstra - Refreshed topics ready for your review. See top comment for details. Thanks |
| * GC drops from 300 MB to 10 MB | ||
|
|
||
| On a typical web server environment, CPU usage is more important than memory, therefore the Server GC is better. If memory utilization is high and CPU usage is relatively low, the Workstation GC might be more performant. For example, high density hosting several web apps where memory is scarce. | ||
|
|
There was a problem hiding this comment.
When an achor is removed, good to see what was using it. I checked and there were 7 articles using this "sc" anchor in this repo. I will create a seperate issue for that and take care of it.
There was a problem hiding this comment.
I always check for anchor usage before removing, and update as needed. My results showed zero hits this time. Not sure why there was a discrepancy between your search and mine.
There was a problem hiding this comment.
Thanks, that is great you check. Sorry, I realize now my comment implied it wasn't checked. I could have worded that in a better way.
The query I used was this:
https://github.com/search?q=repo%3Adotnet%2FAspNetCore.Docs%20performance%2Fmemory%23sc&type=code
Addressing those in #37116
There was a problem hiding this comment.
Thank you. I see now what I missed. I'm not used to links that leave off the file extension. In most other repos, the build validation detects broken bookmark links. Thanks for dbl-checking.
wadepickett
left a comment
There was a problem hiding this comment.
Reviewed. Found a few things to correct or consider. Overall, great work.
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
tdykstra
left a comment
There was a problem hiding this comment.
Looks good, just a few comments and suggestions.
| ms.date: 05/06/2026 | ||
| uid: performance/memory | ||
|
|
||
| # customer intent: As an ASP.NET developer, I want to memory management and garbage collection in ASP.NET Core, so I manage memory in my apps. |
There was a problem hiding this comment.
| # customer intent: As an ASP.NET developer, I want to memory management and garbage collection in ASP.NET Core, so I manage memory in my apps. | |
| # customer intent: As an ASP.NET developer, I want to understand memory management and garbage collection in ASP.NET Core, so I can manage memory in my apps. |
| ## Explore garbage collection in .NET | ||
|
|
||
| The GC allocates heap segments where each segment is a contiguous range of memory. Objects placed in the heap are categorized into one of 3 generations: 0, 1, or 2. The generation determines the frequency the GC attempts to release memory on managed objects that are no longer referenced by the app. Lower numbered generations are GC'd more frequently. | ||
| The GC process allocates heap segments where each segment is a contiguous range of memory. Objects placed in the heap are categorized into one of three generations (Gen): 0, 1, or 2. The generation determines the frequency the GC attempts to release memory on managed objects which the app no longer references. More frequent collections address the lower numbered generations. |
There was a problem hiding this comment.
| The GC process allocates heap segments where each segment is a contiguous range of memory. Objects placed in the heap are categorized into one of three generations (Gen): 0, 1, or 2. The generation determines the frequency the GC attempts to release memory on managed objects which the app no longer references. More frequent collections address the lower numbered generations. | |
| The GC process allocates heap segments where each segment is a contiguous range of memory. Objects placed in the heap are categorized into one of three generations: 0, 1, or 2. The generation determines the frequency of the GC attempts to release memory on managed objects that the app no longer references. The GC addresses the lower-numbered generations more frequently. |
| This article demonstrates common memory use patterns that can be problematic, and suggests alternate approaches. | ||
|
|
||
| ## How garbage collection (GC) works in .NET | ||
| ## Explore garbage collection in .NET |
There was a problem hiding this comment.
| ## Explore garbage collection in .NET | |
| ## Explore garbage collection (GC) in .NET |
| * Demonstrates problematic memory use, and suggests alternative approaches. | ||
| This article demonstrates common memory use patterns that can be problematic, and suggests alternate approaches. | ||
|
|
||
| ## How garbage collection (GC) works in .NET |
| * Can be used to display memory usage patterns of ASP.NET Core apps, but it isn't a supported tool. | ||
|
|
||
| Run MemoryLeak. Allocated memory slowly increases until a GC occurs. Memory increases because the tool allocates custom object to capture data. The following image shows the MemoryLeak Index page when a Gen 0 GC occurs. The chart shows 0 RPS (Requests per second) because no API endpoints from the API controller have been called. | ||
| Run MemoryLeak. Allocated memory slowly increases until a GC occurs. Memory increases because the tool allocates custom object to capture data. The following image illustrates the MemoryLeak Index page when a Gen 0 GC occurs. The chart shows 0 RPS (Requests per second) because no API endpoints from the API controller are called. |
There was a problem hiding this comment.
| Run MemoryLeak. Allocated memory slowly increases until a GC occurs. Memory increases because the tool allocates custom object to capture data. The following image illustrates the MemoryLeak Index page when a Gen 0 GC occurs. The chart shows 0 RPS (Requests per second) because no API endpoints from the API controller are called. | |
| Run MemoryLeak. Allocated memory slowly increases until a GC occurs. Memory increases because the tool allocates a custom object to capture data. The following image shows the MemoryLeak Index page when a Gen 0 GC occurs. The chart shows 0 RPS (Requests per second) because no API endpoints from the API controller have been called. |
| ### Persistent object references | ||
|
|
||
| The GC cannot free objects that are referenced. Objects that are referenced but no longer needed result in a memory leak. If the app frequently allocates objects and fails to free them after they are no longer needed, memory usage will increase over time. | ||
| The GC can't free objects that are referenced. Objects that are referenced but no longer needed result in a memory leak. If the app frequently allocates objects and fails to free them after they aren't needed, memory usage increases over time. |
There was a problem hiding this comment.
| The GC can't free objects that are referenced. Objects that are referenced but no longer needed result in a memory leak. If the app frequently allocates objects and fails to free them after they aren't needed, memory usage increases over time. | |
| The GC can't free objects that are referenced. Objects that are referenced but no longer needed result in a memory leak. If the app frequently allocates objects and fails to free them after they are no longer needed, memory usage increases over time. |
| [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] | ||
|
|
||
| ## Middleware issue when behind an Nginx reverse proxy | ||
| ## Understand middleware issues - Behind an Nginx reverse proxy |
There was a problem hiding this comment.
| ## Understand middleware issues - Behind an Nginx reverse proxy | |
| ## Issues with Nginx reverse proxy |
| ## Troubleshoot response compression | ||
|
|
||
| Use a tool like [Firefox Browser Developer](https://www.mozilla.org/firefox/developer/), which allows setting the `Accept-Encoding` request header and study the response headers, size, and body. By default, Response Compression Middleware compresses responses that meet the following conditions: | ||
| Use a tool like [Firefox Browser - Developer edition](https://www.firefox.com/channel/desktop/developer/) that lets you set the `Accept-Encoding` request header, and study the response headers, size, and body. By default, Response Compression Middleware compresses responses that meet the following conditions: |
There was a problem hiding this comment.
| Use a tool like [Firefox Browser - Developer edition](https://www.firefox.com/channel/desktop/developer/) that lets you set the `Accept-Encoding` request header, and study the response headers, size, and body. By default, Response Compression Middleware compresses responses that meet the following conditions: | |
| Use a tool like [Firefox Browser - Developer edition](https://www.firefox.com/channel/desktop/developer/) that lets you set the `Accept-Encoding` request header and study the response headers, size, and body. By default, Response Compression Middleware compresses responses that meet the following conditions: |
| The GC process allocates heap segments where each segment is a contiguous range of memory. Objects placed in the heap are categorized into one of three generations (Gen): 0, 1, or 2. The generation determines the frequency the GC attempts to release memory on managed objects which the app no longer references. More frequent collections address the lower numbered generations. | ||
|
|
||
| Objects are moved from one generation to another based on their lifetime. As objects live longer, they are moved into a higher generation. As mentioned previously, higher generations are GC'd less often. Short term lived objects always remain in generation 0. For example, objects that are referenced during the life of a web request are short lived. Application level [singletons](xref:fundamentals/dependency-injection#service-lifetimes) generally migrate to generation 2. | ||
| Objects are moved from one generation to another based on their lifetime. As objects live longer, they're moved into a higher generation. As mentioned previously, GC runs less often on higher generations. Short-term lived objects always remain in Gen 0. For example, objects that are referenced during the life of a web request are short lived. Application level [singletons](xref:fundamentals/dependency-injection#service-lifetimes) generally migrate to Gen 2. |
There was a problem hiding this comment.
| Objects are moved from one generation to another based on their lifetime. As objects live longer, they're moved into a higher generation. As mentioned previously, GC runs less often on higher generations. Short-term lived objects always remain in Gen 0. For example, objects that are referenced during the life of a web request are short lived. Application level [singletons](xref:fundamentals/dependency-injection#service-lifetimes) generally migrate to Gen 2. | |
| Objects are moved from one generation to another based on their lifetime. As objects live longer, they're moved into a higher generation. As mentioned previously, GC runs less often on higher generations. Short-lived objects always remain in Gen 0. For example, objects that are referenced during the life of a web request are short lived. Application level [singletons](xref:fundamentals/dependency-injection#service-lifetimes) generally migrate to Gen 2. |

This PR contains light freshness updates to two articles:
moniker range=">= aspnetcore-6.0")For details, see ADO request 568764.
Internal previews