Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

c# 4.0 - Set Maximum Memory Usage C#

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 it leaks; it basically just writes stale pagefiles that I don't have the power to delete. The memory leak doesn't actually cause the program to crash, it just simply eats up all the memory. When it is using all the system's memeory, the OS will just start deleting the old page files and everything runs fine.

If I run my app on a 2gb system, it will use 2 gb and continue to run; same for a 16gb system.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...