限制 C# 应用程序中托管堆的大小

Limiting the size of the managed heap in a C# application(限制 C# 应用程序中托管堆的大小)

本文介绍了限制 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#?

附言

我知道我可以从代码中调用 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.

您可以采取一些措施来限制内存使用量.请参阅此问题以获取一些输入:减少 .NET 应用程序的内存使用?

There are a couple of things you can do to limit the memory usage. Please see this question for some input: Reducing memory usage of .NET applications?

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

本文标题为:限制 C# 应用程序中托管堆的大小

基础教程推荐