Avoid Mono Cryptic GC Error Messsage

2019-04-09 22:15发布

问题:

I am currently running a program in mono (Mac OSX) that reads through a very large data file and creates summary statistics after aggregation.

Mysteriously, I get the following error message at some point in the program:

Garbage collector could not allocate 16384 bytes of memory for major heap section

I was hoping for an OOM exception, or something else I could work with. I have tried upping the max-heap-size with:

export MONO_GC_PARAMS=max-heap-size=4g

but, it winds up telling me that I need to set it to an integer, trying to input the value manually with appropriate zeros leads to a gdb dump at the start of execution.

The thing that annoys me about this is that I think at this particular section of code where it breaks, there is 16384 bytes available on the machine, and i think it should be able to GC just fine and get more memory.

Does anyone know how to fix this?

回答1:

If you're using mono 2.10.8 or later you could try executing the mono application using the more advanced sgen garbage collector which is not as conservative as the default GC.

It solve some problems with memory leakage that I was having, perhaps you're having a related issue.

To run using sgen you have to ensure that that mono-runtime-sgen is installed then use the following command line parameter when executing your program:

mono --gc=sgen YourProgram.exe