7

imagine you have an application (single process) written in c#

By default the application is allocating huge virtual memory, far more than it needs (for example the resident memory is about 10mb, while virtual memory is about several GB).

In Java it's possible to use an option to limit this with java -mx128m

How can I do the same for .net / mono application? And the bonus question: is it possible to enforce / change the GC options to always keep as low memory usage as possible (collect as soon as possible, not when system is running out of memory)

basically my goal is to create a .net application with minimal memory footprint

EDIT: in order to make it more clear I insert this scenario, given that nearly every .net application seems to have similar problem:

I run a monodevelop, which is c# application under mono - it eats 1800 MB of virtual memory, while it only uses 291 MB of resident memory. That means the application is using only less than 300mb of memory but it asked for 1800MB for unknown reason. This reason is what I would like to discover as well as the way how to prevent it doing so.

That probably isn't problem for most of users, but it may be problem for applications running on clusters like SGE when task is limited by virtual memory.

4

1 回答 1

3

Mono 有几个标志用于设置内存的上限,例如 java。例如,当我运行集群作业时,我设置了以下环境变量。

setenv MONO_GC_PARAMS 最大堆大小=8G

您可以在此处查看此问题的更多选项:

Mono GC max-heap-size 没有记录。在生产中使用是否安全?

于 2013-12-17T16:59:11.983 回答