# mono ios莫名其妙闪退的解决方法

    ……………………
    0x01e394ac monoeg_g_log + 208 6 TrackAboutIOS
0x01d11664 get_numerous_trampoline + 160 7 TrackAboutIOS
……………………
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
=================================================================

On device we generate all the necessary code at build time in a process known as Ahead of Time compilation (similar to Microsoft's ngen), because we're not allowed to jit code on devices. Unfortunately there are a few things that cannot be determined statically - for instance generic interfaces might need different vtables depending on which type the interface is instantiated with. (For this case it is technically possible to determine the maximum number of vtables, but the number would be potentially enormous - multiply the number of generic interfaces times the number of types in your app...). We cannot allocate memory for these vtables dynamically at runtime, so we've picked a reasonable default and allow the user to increase this value if they run into issues. This is the basic theory for the trampolines (the exact problem is a bit different, depending on the type of trampolines, but that's not really important).

So you can add as many trampolines as you want, but memory usage will increase. That's also all there is to it: the app will not get slower (unless if the increased memory usage causes it to run slower, due to out-of-memory warnings, etc). It also means that you only have to increase the number of trampolines of the type you're actually having problems with, if you increase the others you'll increase the size of your executable needlessly.


因为mono不允许在苹果设备上即时编译代码，所以在编译的时候mono会通过AOT编译技术直接编译为ARM汇编代码。但在编译的时候仍有一些无法静态确定的事情：例如泛型接口可能需要不同的虚拟表（运行时存放执行方法的集合），这取决于接口被实例化时的类型。（对于这种情况，从技术上讲确定虚拟表的最大数量是可能的，但是这数量可能会是庞大的--即泛型接口数乘以应用中类型数）……我们无法为这些虚拟表在运行时动态的分配内存，所以我们指定了一个合理的默认值并且允许用户在运行时出现问题的情况下增加默认值。这就是蹦床的基本理论（实际情况略微不同，这依赖于蹦床数的类型，但这并不重要）

Ran out of trampolines of type 0
If you get this message while running device,  You can create more type 0 trampolines (type SPECIFIC) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "ntrampolines=2048"

The default number of trampolines is 1024.  Try increasing this number until you have enough for your application.

Ran out of trampolines of type 1
If you make heavy use of recursive generics, you may get this message on device.  You can create more type 1 trampolines (type RGCTX) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "nrgctx-trampolines=2048"

The default number of trampolines is 1024.  Try increasing this number until you have enough for your usage of generics.

Ran out of trampolines of type 2
If you make heavy use interfaces, you may get this message on device.  You can create more type 2 trampolines (type IMT Thunks) by modifying your project options "iPhone Build" section.  You want to add extra arguments for the Device build targets:

-aot "nimt-trampolines=512"

The default number of IMT Thunk trampolines is 128.  Try increasing this number until you have enough for your usage of interfaces.

Ran out of trampolines of type 0
如果你再运行时，输出这个错误，你可以在项目option--iphone build处添加额外的参数-aot "ntrampolines=2048"
这个参数默认值为1024，试着增加这个值直到满足你的应用的需求。
Ran out of trampolines of type 1
如果你使用了过多的泛型嵌套，如List<T>中还有List<T>成员，你可以同上通过添加额外的参数-aot "nrgctx-trampolines=2048" 来解决。
蹦床类型1的默认值为1024.
Ran out of trampolines of type 2
如果你界面操作频繁，你可以通过添加额外的参数-aot "nimt-trampolines=512" 来解决。
这里的默认值为128.
posted @ 2013-09-14 00:11 flowbywind 阅读(...) 评论(...) 编辑 收藏