使用mono进行ios开发也有一年了,一直有个头疼的问题是闪退,而且闪退的时候并没有抛出明确的错误。

前两天在调试一个bug的时候,在序列化的时候又莫名其妙的闪退,后来在一位大神(博客地址)的指导下,发现了解决方案!

遇到这种闪退,一般在Application output中输出错误如下:

    ……………………
    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
used by your application.
=================================================================

而且这种错误是随机的,有时候正常运行,有时候不正常,在上文输出错误内容里我们看到trampoline这个单词,而第一句monoeg_g_log 这句话是说系统在尝试记录错误到错误日志,基于这种情况下,我们可以判定这是mono的默认蹦床(trampoline)数小于了你应用需要的蹦床数。

关于蹦床数的解释,这里Rolf Bjarne Kvinge给了相应的解释:相应链接

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

所以你可以按你的需要尽可能的增加蹦床数,但是内存的使用会增加。 应用一般不会变慢(除非内存的使用增多导致了内存不足,从而引起运行变慢)。这也同时意味着你只仅仅需要增加发生问题那块对应的蹦床类型的数目。如果你增加了其他蹦床类型的数目,你也会不必要的增多了执行的体积。

看完这个,我想你对蹦床数有了一定了解,那如何设置呢!

打开xamarin studio ,在项目文件上右键option,展开下图,在arguments参数的地方,输入:-aot "nrgctx-trampolines=4096" -aot "nimt-trampolines=4096" -aot "ntrampolines=4096"

请看下图:

我们在上面看到了-aot "nrgctx-trampolines=4096" -aot "nimt-trampolines=4096" -aot "ntrampolines=4096"这几个输入参数,那这几个参数相对应的意思是什么呢?

这里官网给了我们解释:链接地址

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.


mono ios莫名其妙闪退的解决方法的更多相关文章

  1. iOS开发-闪退问题-解决之前上架的 App 在 iOS 9 会闪退问题

    最新更新:(2015.10.02) 开发环境: Delphi 10 Seattle OS X El Capitan v10.11 需使用下列 HotfixID: 30398, PAServer Hot ...

  2. 神秘代码让iPhone微信闪退的解决方法

    14号晚,很多人的微信朋友圈中出现了这样几句话“听说苹果手机点全文就会闪退”,下方有好几行空白,需要点击“全文”才能看到,但是一旦你是在iPhone手机微信上点击“原文”后就直接闪退了,而用Andro ...

  3. 〖Android〗从Android Studio转为Eclipse开发项目运行程序闪退的解决方法

    很久没有撸Android App开发了- 最近把一个月前通过反编译.二次修改的Android SSHD项目进行简单修改一下: 突然发现迁移项目时,报了一个错误,同时还出现了闪退情况: - ::): t ...

  4. 【OS_Windows】Win10应用商店闪退和点击Cortana搜索框闪退的解决方法

    Windows10用户遇到了打开应用商店时闪退和点击Cortana小娜搜索框闪退的问题,并且在微软社区求助,得到了一种可行的解决方法,那就是查看Network List Service(网络列表服务) ...

  5. Android 开发之异常处理篇(一):SDK Manager 闪退的解决方法

    这个问题困扰了我很久,之前没解决,就放一放.后来我又专门拿了一个下午来找解决方法,终于搞定! 我的解决方法是修改 android.bat,直接指定java.exe所在位置,不用去调用find_java ...

  6. Windows 7 x64环境下SDK Manager闪退的解决方法

    1.下载并解压:http://dl.google.com/android/adt/adt-bundle-windows-x86_64-20140702.zip 2.安装JDK,否则SDK Manage ...

  7. 记一次MyEclipse闪退的解决方法

    http://www.th7.cn/Program/java/201408/262487.shtml ———————————————————————————————————————————————— ...

  8. MySQL:输入密码后闪退的解决方法

    原因:MySQL服务没有启动 解决方法:在 "服务" 中启动MySQL

  9. VS2017创建控制台应用后,编写完代码调试正常,使用exe文件直接执行出现闪退情况解决方法。

    这是因为代码中包含的相对路径的原因. 解决办法:把项目中包含的所有相对路径修改为绝对路径. (个人觉得因为直接执行exe文件,默认打开在C盘的用户目录下.) 例如: std::string DATA_ ...

随机推荐

  1. Ajax 概念 分析 举例

    Ajax是结合了访问数据库,数据访问,Jquery 可以做页面局部刷新或者说是页面不刷新,我可以让页面不刷新,仅仅是数据的刷新,没有频繁的刷页面,是现在比较常用的一种方式做页面那么它是怎么实现页面无刷 ...

  2. node中的cmd规范

    你应该熟悉nodejs模块中的exports对象,你可以用它创建你的模块.例如:(假设这是rocker.js文件) exports.name = function() { console.log('M ...

  3. MVC5 网站开发之九 网站设置

    网站配置一般用来保存网站的一些设置,写在配置文件中比写在数据库中要合适一下,因为配置文件本身带有缓存,随网站启动读入缓存中,速度更快,而保存在数据库中要单独为一条记录创建一个表,结构不够清晰,而且读写 ...

  4. Unity3D框架插件uFrame实践记录(二)

    5.创建属性和命令 本小节主要内容包括: 在Element节点上创建属性数据 在Element节点上创建命令数据 5.1.在Element节点上创建属性数据 在这里,我们首先为Login节点中的属性( ...

  5. CSS 3学习——box-sizing和背景

    box-sizing 在CSS 2中设置元素的width和height仅仅是设置了元素内容区的宽和高,元素实际的尺寸是margin + border + padding + 内容区. CSS 3(截止 ...

  6. 编写高质量代码:改善Java程序的151个建议(第8章:多线程和并发___建议126~128)

    建议126:适时选择不同的线程池来实现 Java的线程池实现从根本上来说只有两个:ThreadPoolExecutor类和ScheduledThreadPoolExecutor类,这两个类还是父子关系 ...

  7. 使用EF CodeFirst 创建数据库

    EntityFramework 在VS2015添加新建项时,选择数据->ADO.NET 实体数据模型,有一下选项 来自数据库的EF设计器,这个就是我们最常用的EntityFramework设计模 ...

  8. Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器)

    一. 准备工作 1. 树莓派主板 型号:树莓派3 B型 处理器:四核64位ARM Cortex-A53 CPU 内核架构:ARMv8 2. 一张大于8G的TF卡(本人用的是32G的,也作为PiLFS用 ...

  9. Linux上课笔记--随手记Linux命令

    初次接触Linux就是感觉这系统不够友好不够人性化,因为首先接触电脑就是win,图形化界面什么操作都可以清晰看到.随着更多的接触越来越发现Linux的强大,虽然我只是一个小白,可我就是爱上他了.现在就 ...

  10. Akka.NET v1.0 已发布,支持Mono

    Akka.NET 是Java/Scala 流行框架Akka的一个 .NET 开源移植.可用于构建高并发,分布式和容错事件驱动的应用在 .NET 和 Mono 平台之上.Akka.NET 经过一年多的努 ...