在C#应用程序限制的托管堆的大小 [英] Limiting the size of the managed heap in a C# application

查看:158
本文介绍了在C#应用程序限制的托管堆的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以配置我的C#应用​​程序,以限制其内存消耗,比如说,200MB? IOW,我不想等待自动GC(这似乎使堆增长远远超过实际需要的这个应用程序)。

Can I configure my C# application to limit its memory consumption to, say, 200MB? IOW, I don't want to wait for the automatic GC (which seems to allow the heap to grow much more than actually needed by this application).

我知道,在Java中有一个命令行开关,您可以传递给实现这个JVM ..有在C#中的等价?

I know that in Java there's a command line switch you can pass to the JVM that achieves this.. is there an equivalent in C#?

P.S。

我知道我可以调用从code中的GC,但是这件事情我宁可不要定期做。我宁愿在启动时设定一次,它在某种程度上忘记了。

I know that I can invoke the GC from code, but that's something I would rather not have to do periodically. I'd rather set it once upon startup somehow and forget it.

推荐答案

我不知道有任何这样的选择正规的CLR。我猜想,你可以控制这个,如果你实现自己的CLR的主机。

I am not aware of any such options for the regular CLR. I would imagine that you can control this if you implement your own CLR host.

不过,我不同意你怎么堆增长评估。堆增长,因为您的应用程序分配和持有的对象。

However, I disagree in your assessment of how the heap grows. The heap grows because your application is allocating and holding on to objects.

有几件事情可以做,以限制内存的使用。请看到这个问题的一些输入:<一href="http://stackoverflow.com/questions/1343374/reducing-memory-usage-of-net-applications/1343394#1343394">http://stackoverflow.com/questions/1343374/reducing-memory-usage-of-net-applications/1343394#1343394

There are a couple of things you can do to limit the memory usage. Please see this question for some input: http://stackoverflow.com/questions/1343374/reducing-memory-usage-of-net-applications/1343394#1343394

这篇关于在C#应用程序限制的托管堆的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆