A memory leak issue in .NET apps on Windows arises from improper use of Microsoft.Extensions.Configuration APIs, especially after upgrading to .NET 7+. This leak causes gradual memory growth, potential OutOfMemoryExceptions, and performance drops, mainly impacting Gen2 heap regions in the garbage collector. Unique :

Memory Leak Alert in .NET Apps Using Microsoft.Extensions.Configuration on Windows
If you’ve recently upgraded your .NET app to version 7 or above, or even started fresh, you might face a sneaky memory leak. This issue, spotted mainly in ASP.NET Core but possible in any .NET app, causes memory to grow over time, potentially crashing your app with an OutOfMemoryException.
What’s New and Why It Matters
The root cause lies in how .NET 7+ manages memory differently than its predecessors. While .NET 6 and earlier use large heap-specific segments, .NET 7 and beyond switch to smaller, reusable regions. This change affects garbage collection and reveals leaks that were previously hidden.
Importantly, this leak appears to be specific to Windows environments. If your app runs on Linux or macOS, you’re likely safe, but it’s still worth checking.
“This particular problem is one I have come across several times here in support.” – Matt Hamrick, IIS Support Blog
How to Spot the Leak
- Memory usage slowly climbs, even with steady or low traffic.
- GC stats show a large amount of free memory in Gen2 that never shrinks.
- Memory dumps reveal many pinned byte arrays and FileSystemWatcher+AsyncReadState objects.
- Eventually, your app might throw OutOfMemoryException errors.
Early detection is key. Monitoring tools and regular memory dump analysis can catch this before users notice.
Deep Dive: What’s Happening Under the Hood
Using WinDbg and .NET’s SOS extension, the investigation reveals Gen2 heaps bloated with many 4MB committed regions full of free space. Despite this, memory isn’t reclaimed, causing the leak.
Here’s a snapshot from the heap statistics:
Gen2 Committed Space: ~4GB Free Space within Gen2: ~3.6GB
This indicates a lot of memory is reserved but unused, trapped by improper API usage.
Why Does This Leak Occur?
The leak stems from incorrect handling of Microsoft.Extensions.Configuration APIs, which pin objects in memory and prevent the garbage collector from reclaiming space. This is exacerbated by .NET 7+’s memory region strategy.
As Matt Hamrick notes,
“Most of these signs often appear well before the system runs out of memory, so early detection via monitoring tools and periodic dump analysis can help prevent user-facing impact.”
What You Should Do Now
First, audit your app’s use of Microsoft.Extensions.Configuration APIs. Avoid patterns that cause pinned objects to accumulate. Next, implement monitoring to track memory growth over time.
Finally, keep your .NET runtime updated. While this issue is documented for .NET 8, similar concepts apply to .NET 7 and beyond.
Wrapping Up
Memory leaks can silently degrade your .NET app’s performance, especially after upgrading to .NET 7+. By understanding how memory management changed and spotting early warning signs, you can avoid costly outages.
Stay vigilant, monitor your app’s memory footprint, and review your configuration code to keep your .NET apps running smoothly on Windows.
From the New blog articles in Microsoft Community Hub