I have problem with memory management in my API applications hosted on IIS. The server runs 40 applications, a mix of .NET Framework 4.8 and .NET 8. The problem is that .NET 8 applications consume memory and don’t release it back to the operating system effectively.
Although the Garbage Collector (GC) is running, the memory often remains allocated within the process as free memory but is not returned to the OS. This behavior leads to high memory usage across processes, and some applications eventually throw OutOfMemoryException.
Additionally, before the GC runs, Generation 0 often grows to significant sizes, sometimes reaching hundreds of megabytes or even several gigabytes. This excessive memory usage is causing major performance issues, and I need a solution to optimize memory usage, force .NET 8 applications to release unused memory more effectively, and mitigate these problems.
The applications are using EF Core 8.0.11 (only reading). DbContext is registered as scoped.
return dbContext.Speakers.AsNoTracking().OrderBy(s => s.Name).ThenBy(s => s.Id);
Do you have any recommendations for improving memory management or configuring the GC to better handle this scenario?
1