Set Maximum Memory Usage C#

后端 未结 2 1296
忘了有多久
忘了有多久 2020-12-21 04:44

I have an application that must use a library that I didn\'t write and I don\'t have the power to change it. Basically there is a memory leak, so the long it runs, the more

相关标签:
2条回答
  • 2020-12-21 05:25

    Have also a look at Process Governer: http://lowleveldesign.wordpress.com/2013/11/21/set-process-memory-limit-with-process-governor/. I wrote this tool to test memory leaks in my applications. The process running with a memory limit will throw OutOfMemory if it exceeds it.

    0 讨论(0)
  • 2020-12-21 05:30

    That is a per-process limitation in Windows. Each process gets ~2GB virtual address space (that is what Heap makes use of) in a 32-bit machine. And I am afraid there is not much you can do about it.

    Roughly, CLR is able hold upto ~1.6GB of objects in memory. That should be enough for most of the applications. If not, then you need to work on your application.

    In my case, I faced a similar problem and then used SqlDataReader to fetch objects in a specified chunk size, process it, compute it, clean it from memory, and then fetch another chunk.

    There is also a detailed article on MSDN - Investigating Memory Issues

    Hope this would be helpful.

    0 讨论(0)
提交回复
热议问题