Bug 25631 - Mono throws OutOfMemoryException on Ubuntu but not OSX or Windows
Summary: Mono throws OutOfMemoryException on Ubuntu but not OSX or Windows
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-12-28 16:22 UTC by Ted
Modified: 2015-01-03 07:42 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ted 2014-12-28 16:22:42 UTC
I am unsure whether this is a bug or a configuration problem, but I don't know how to go about finding a solution.

I have installed Mono on an Ubuntu server and "Hello World" is working, but a simplified application that does some array handling and runs without problem under Mono on OSX or Windows is giving:

    System.OutOfMemoryException: Out of memory.
      at (wrapper alloc) object:AllocVector (intptr,intptr)

It should not require more than a few MB of memory. The server has 4GB of RAM.

Running again under alloc profile gives a different exception:

    System.OverflowException: Number overflow.
      at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)

The problem is inconsistent, sometimes the code runs once but then not a second time. Sometimes it doesn't work for the first time. Sometimes it fails in a different method but for the same reason.

The program and full output can be downloaded at http://dev.intelorca.co.uk/2014/gacj_allocproblem.zip It would be good to see if anyone else has problems running the program under mono (/linux) and can provide any insight on what the problem is. Any pointers to configuring Mono to run better on Ubuntu would also be helpful if it is a configuration problem.

The program should output "Cambridge Surprise Major" 128 times.
Comment 1 Zoltan Varga 2015-01-02 18:46:10 UTC
I get:
Unhandled Exception:
System.OutOfMemoryException: Out of memory.
  at (wrapper alloc) object:AllocVector (intptr,intptr)
  at GACJ.Ringing.Methods.MethodClassifier.DetermineCycles () [0x00000] in <filename unknown>:0 
  at GACJ.Ringing.Methods.MethodClassifier.Classify () [0x00000] in <filename unknown>:0 
  at GACJ.Ringing.Methods.MethodClassifier.Classify (GACJ.Ringing.Methods.Method method) [0x00000] in <filename unknown>:0 
  at GACJ.Ringing.Methods.Method.Classify () [0x00000] in <filename unknown>:0 
  at Test.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

The DetermineCycles () method tries to allocate a String[] array with length 4294967304.
Comment 2 Ted 2015-01-02 20:26:40 UTC
Thanks for trying it Zoltan,

4294967304 = 0x100000008

It should be allocating a size of 8, but bit 32 seems to be set...
What could be causing this to happen only on this particular platform and not necessarily the first time the code is run?
Comment 3 Zoltan Varga 2015-01-02 22:29:45 UTC
Fixed in mono master 9e03c10d8fefea9210ca015cf484e819623c0a1a.
Comment 4 Ted 2015-01-03 07:42:18 UTC
Thanks, I can confirm this fix has worked.