[英]Xamarin.Mac obscure SIGSEGV
我在xamarin.mac
遇到了晦涩的段xamarin.mac
,这是(无用的)stacktrace:
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
之后,会发生崩溃,该处理会进行大量处理。
很难确定到底是什么导致了崩溃。
有任何想法吗 ?
该错误是由于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
就是这样!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.