2

我需要为 Mono 使用的内存设置一个上限。

根据博客,可以使用该参数max-heap-size来限制内存使用量。根据实验,根据代码,它确实做了我想要的。

但是,此选项未记录在案

因此:在生产中依赖此选项是否安全(或者它是否有我看不到的缺点,例如:不保证在未来版本的 Mono 中仍然可用)?

4

2 回答 2

8

它已记录在案,这是获取文档的一种方法:exportinvalid MONO_GC_PARAMS, start mono

export MONO_GC_PARAMS=xxx
mono sample.exe

并获得帮助:

Warning: In environment variable `MONO_GC_PARAMS': Unknown option `xxx`. - Ignoring.

MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:
  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)
  soft-heap-limit=n (where N is an integer, possibly with a k, m or a g suffix)
  nursery-size=N (where N is an integer, possibly with a k, m or a g suffix)
  major=COLLECTOR (where COLLECTOR is `marksweep', `marksweep-conc', `marksweep-par', 'marksweep-fixed' or 'marksweep-fixed-par')
  minor=COLLECTOR (where COLLECTOR is `simple' or `split')
  wbarrier=WBARRIER (where WBARRIER is `remset' or `cardtable')
  stack-mark=MARK-METHOD (where MARK-METHOD is 'precise' or 'conservative')
  [no-]cementing
  evacuation-threshold=P (where P is a percentage, an integer in 0-100)
  (no-)lazy-sweep
 Experimental options:
  save-target-ratio=R (where R must be between 0.10 - 2.00).
  default-allowance-ratio=R (where R must be between 1.00 - 10.00).

如您所见max-heap-size,已列出,而不是在Experimental Options. 所以我会说它是安全的。

于 2013-10-15T07:49:37.043 回答
0

它记录在单声道手册页中:

设置堆的最大大小。大小以字节为单位指定,并且必须是 2 的幂。后缀k',m' 和 `g' 可分别用于指定千字节、兆字节和千兆字节。限制是托儿所、主堆和大对象堆的总和。一旦达到限制,应用程序将在尝试分配时收到 OutOfMemoryExceptions。由于内部碎片,无法使用 max-heap-size 中设置的全部内存来满足单个分配。默认情况下,堆限制被禁用,GC 将尝试使用所有可用内存。

于 2017-05-10T11:55:25.103 回答