Bug 10005 - Mono crash instead throwing OutOfMemory exception
Summary: Mono crash instead throwing OutOfMemory exception
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-02-03 15:34 UTC by Sergey Zhukov
Modified: 2013-02-13 17:05 UTC (History)
4 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 Sergey Zhukov 2013-02-03 15:34:05 UTC
Mono crashes in such test case:

using System;
using System.Collections.Generic;

namespace mt3
	class MainClass
		public static void Main(string[] args)
			List<byte[]> test = new List<byte[]>();
			for (int i=0; i<int.MaxValue; i++)
				test.Add(new byte[10000]);

mono-sgen ./mt3.exe
* Assertion at sgen-gc.c:2221, condition `mem' not met


  at (wrapper managed-to-native) object.__icall_wrapper_mono_gc_alloc_vector (intptr,intptr,intptr) <0xffffffff>
  at (wrapper alloc) object.AllocVector (intptr,intptr) <0xffffffff>
  at mt3.MainClass.Main (string[]) <0x0004b>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

instead of crashing mono should raise OutOfMemory exception

Mono JIT compiler version (Debian
Ubuntu 10.04 (32 bit)
4Gb of RAM
Comment 1 Sergey Zhukov 2013-02-05 05:20:43 UTC
I ran this test case in mono 3.0.4. The result is correct.

 mono-sgen ./mt3.exe

Unhandled Exception:
[ERROR] FATAL UNHANDLED EXCEPTION: System.OutOfMemoryException: Out of memory
  at (wrapper managed-to-native) object:__icall_wrapper_mono_gc_alloc_vector (intptr,intptr,intptr)
  at (wrapper alloc) object:AllocVector (intptr,intptr)
  at mt3.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 

Mono JIT compiler version 3.0.4 (master/0e6393e Mon Feb  4 14:03:01 PST 2013)
Ubuntu 12.04 (32 bit)
768M of RAM

Also, I noticed difference in memory allocation. mono-sgen 2.10.8 allocates only free memory, without using swap and crashes in case of out of memory. mono-sgen 3.0.4 allocates free memory and whole free swap and only then throw OutOfMemoryException or was killed by oom killer.
Comment 2 Rodrigo Kumpera 2013-02-12 12:40:14 UTC
mono does alloc as much memory as you let it to. This is the normal behavior of any program you run.

I suggest you limit the amount of managed memory mono can allocate and in the meanwhile try to find the memory leaks in your app.
Comment 3 Sergey Zhukov 2013-02-13 14:58:19 UTC
I don't understand your point. Do you mean, that hard crash of mono instead of throwing OutOfMemoryException is normal behaviour? In this bug I didn't tell about memory leaks, what I've just said, that mono 2.10 must throw OutOfMemoryException when there is no enough memory but not to crash.
Comment 4 Rodrigo Kumpera 2013-02-13 17:05:48 UTC
Use mono 3.0.0. 2.10 is not longer publicly maintained.