High memory consumption of .Net 6 app on Linux

Denis Lohachev 5 Reputation points
2023-12-16T12:20:35.8333333+00:00

I encountered a very serious problem when switching from Windows to Linux (Ubuntu). The problem is very high memory consumption. I first noticed an increase in memory consumption on Windows when moving from .Net Framework to .Net Core 5. But then this was not much of a problem and was acceptable since the increase was not large. The .Net Framework application consumed approximately 150-200 megabytes and the .Net Core 5 application consumed approximately 250-350 megabytes. But when I switched to Linux, the consumption increased many times over. To make the transition, I switched to .Net 6. After running the application on Linux, I noticed that memory grows over time and does not decrease; with long-term operation of the application, memory consumption can reach 6-8 gigabytes. After doing a memory dump, I noticed that almost 90% was taken up by unmanagement memory. There are about 50 instances of this application running on my server, and they quickly consume all the memory, which leads to application crashes. I have no idea why this is happening, it seems that Garbage collection is not freeing the reserved memory. For information, on Windows under IIS the application worked in 32-bit on Linux in 64-bit.

I tried changing Garbage collection settings such as (DOTNET_GCConserveMemory and DOTNET_gcServer), but it didn't helpDump

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,921 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,166 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 66,706 Reputation points
    2023-12-16T17:11:18.62+00:00

    The increase in unmanaged memory probably means your code is not properly calling Dispose() on instances that allocate unmanaged memory.

    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using


  2. Bruce (SqlWork.com) 66,706 Reputation points
    2024-08-19T16:31:52.9266667+00:00

    as you are leaking unmanaged memory, you will need to track down the component. you might try this thread:

    https://github.com/dotnet/runtime/issues/95922


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.