简体   繁体   中英

.net 6 unmanaged memory is not release

I have console application on .net6 located in docker container. This application generate a lot of strings and save it to files. (Application generate read database objects and create html, after that union on one zip archive)

I will check all streams closing and dispose For example I made like this:

 await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(html));

Html generated manually using StringBuilder

And i have a problem with increase unmanaged memory. This memory don't released. I checked twice all streams as disposed all good. But why unmanaged memory is not decrease don't understand.

This is image with memory snapshot on dotMemory. Maybe somebody can explain me which part i lost or provide info about some articles why it happens. Thanks so much在此处输入图像描述

There is no straightforward answer to this problem, but there are a few workarounds you could try.

Make sure that you are disposing of all objects that implement the IDisposable .

There could be a problem with external libraries if you are using them.

There could be some objects which are holding a reference to the other objects and causing the memory leak, you can use some other profile tools like .NET Memory Profiler

Note : You could also try GC.Collect() to manually trigger the garbage collection, but be aware it's not a recommended approach, it can impact the performance in another way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM