我在xamarin.mac中遇到了一个模糊的段错误,这是(无用的)堆栈跟踪:
at <unknown> <0xffffffff>
at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <0xffffffff>
at MonoMac.AppKit.NSApplication.Main (string[]) <0x00097>
at gitbookpro.mac.MainClass.Main (string[]) <0x00017>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>在处理NSOutlineView上的SelectionDidChange后发生崩溃,这会进行相当多的处理。
很难确定到底是什么导致了这次崩溃。
有什么想法吗?
发布于 2014-10-22 18:20:35
该错误是由于,C#对象被错误地清理了收集的而导致的。
它们被垃圾收集,因为这些对象被返回到objective-c代码(本机代码),并且由于C#中没有保留引用,垃圾收集器将删除它们。
这就是发生的事情:
1. create C# obj 2. return obj to native code 3. ... wait a little bit ... 4. turn native object back into to C# obj (in event handlers etc ...) 5. Access C# obj <= This would fail occasionally since it was being garbage collected during step #3
你应该做的是:
1. create C# obj 1bis. Keep an extra reference to the object somewhere (in an Dictionary for example) 2. return obj to native code 3. ... wait a little bit ... 4. turn native object back into to C# obj (in event handlers etc ...) 4bis. Remove extra reference 5. Access C# obj <= This would fail occasionally since it was being garbage collected during step #3
就是这样!
https://stackoverflow.com/questions/26495348
复制相似问题