Limiting the size of the managed heap in a C# application(限制 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# 应用程序中托管堆的大小
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
