Set maximum c # memory usage

I have an application that should use a library that I did not record, and I have no way to change it. Basically there is a memory leak, so if it lasts a long time, the more it flows; it basically just writes outdated page files that I cannot delete. A memory leak does not actually cause the program to crash, it just simply absorbs all the memory. When it uses the entire system memeory, the OS will just start deleting old page files, and everything will work fine.

If I run the application on a 2gb system, it will use 2 gb and continue to work; for a system with 16 GB.

Is there a way to set the amount of memory that the application can use?

+4
source share
2 answers

This is a limitation for every process in Windows. Each process receives ~ 2 GB of virtual address space (that is, that uses a bunch) in a 32-bit machine. And I'm afraid you can't do it.

Roughly speaking, the CLR can hold up to ~ 1.6 GB of objects in memory. This should be sufficient for most applications. If not, then you need to work with your application.

In my case, I ran into a similar problem and then used SqlDataReader to retrieve objects at a given block size, processed it, calculated it, cleared it from memory, and then extracted another fragment.

There is also a detailed article on MSDN - Researching Memory Problems

Hope this will be helpful.

+3
source

See also the Process Governer: http://lowleveldesign.wordpress.com/2013/11/21/set-process-memory-limit-with-process-governor/ . I wrote this tool to check for memory leaks in my applications. A process running with a memory limit will call OutOfMemory if it exceeds it.

0
source

Source: https://habr.com/ru/post/1392399/


All Articles