gpt4 book ai didi

ios - Mono Boehm vs SGen GC

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:28 25 4
gpt4 key购买 nike

我在以下环境中开发了一个应用程序(在我的错误中重命名为 MyApplication 以保护隐私):

  • 单点触控 2.1
  • MonoDevelop 2.4.2
  • MacOS 10.6.8
  • iOS SDK 4.3

工作正常。

现在我尝试使用 MonoDevelop 2.8.8.4 迁移到 iOS 5.0/5.1 和 Monotouch 5.2.5。我的应用程序立即崩溃并出现以下错误:

Stacktrace:

at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34
at MyApplication.Application.Main (string[]) [0x00000] in /Users/MyPC/Projects/Test/MyApplication/Main.cs:19
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

native 堆栈跟踪:

0   MyApplication                            0x000908fc mono_handle_native_sigsegv + 284
1 MyApplication 0x00005c98 mono_sigsegv_signal_handler + 248
2 libSystem.B.dylib 0x9138145b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 libobjc.A.dylib 0x02958753 prepareForMethodLookup + 93
5 libobjc.A.dylib 0x0294f069 lookUpMethod + 86
6 libobjc.A.dylib 0x0294f1d6 _class_lookupMethodAndLoadCache + 40
7 libobjc.A.dylib 0x029620e3 objc_msgSend + 87
8 UIKit 0x01cba799 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x01cbcc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x01cbba1c -[UIControl touchesBegan:withEvent:] + 277
11 UIKit 0x01c4ed41 -[UIWindow _sendTouchesForEvent:] + 395
12 UIKit 0x01c2fc37 -[UIApplication sendEvent:] + 447
13 UIKit 0x01c34f2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x03fa5992 PurpleEventCallback + 1550
15 CoreFoundation 0x00df8944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00d58cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00d55f83 __CFRunLoopRun + 979
18 CoreFoundation 0x00d55840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00d55761 CFRunLoopRunInMode + 97
20 GraphicsServices 0x03fa41c4 GSEventRunModal + 217
21 GraphicsServices 0x03fa4289 GSEventRun + 115
22 UIKit 0x01c38c93 UIApplicationMain + 1160
23 ??? 0x090a61fc 0x0 + 151675388
24 ??? 0x090a60c8 0x0 + 151675080
25 ??? 0x090a59c0 0x0 + 151673280
26 ??? 0x090a590c 0x0 + 151673100
27 ??? 0x090a5997 0x0 + 151673239
28 MyApplication 0x0000a002 mono_jit_runtime_invoke + 722
29 MyApplication 0x00169efe mono_runtime_invoke + 126
30 MyApplication 0x0016dfe4 mono_runtime_exec_main + 420
31 MyApplication 0x00173405 mono_runtime_run_main + 725
32 MyApplication 0x00067205 mono_jit_exec + 149
33 MyApplication 0x002116d5 main + 2837
34 MyApplication 0x00003055 start + 53
35 ??? 0x00000004 0x0 + 4

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.

部署到iOS SDK 4.3也是一样的。我认为这可能是这里提到的新 GC SGen 的问题 http://www.infoq.com/news/2012/02/MonoTouch-SGen

更新:事实上,错误在警报显示中显示为 lv.Message = "Copy...";

Class Handle: the requested operation cannot be completed because the object has been garbage collected

我该如何解决?

最佳答案

在 MonoTouch 4 中,GC 执行得更积极,以尽早捕获某种类型的编程错误:确保 native 对象不会被 GC 过早释放。

最常见的模式是在方法中声明变量:

void Method ()
{
var view = new UIView ();
otherNativeObject.NativeProperty = view;
}

这里发生的是托管 GC 没有看到 otherNativeObject 有对 View 的引用,所以当方法执行完毕时,GC 将释放 View 。稍后 otherNativeObject 将尝试使用该 View ,您最终会遇到与您报告的崩溃类似的崩溃(确切的堆栈跟踪和消息会有所不同,具体取决于访问释放的 native 对象的位置)。

上面例子的修复很简单,只需将 View 设为类变量即可:

UIView view;
void Method ()
{
view = new UIView ();
otherNativeObject.NativeProperty = view;
}

现在 GC 将无法在方法退出时释放 View 。

请注意,这种崩溃在 MonoTouch 4 中并不是新出现的,使 GC 更具侵略性的效果是您会在调试时看到问题,而不是在客户(非常随机地)崩溃时从客户那里听到它。

关于ios - Mono Boehm vs SGen GC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10008953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com