[英]Xamarin.Mac obscure SIGSEGV
I'm encountering an obscure segfault with xamarin.mac
, this is the (unhelpful) stacktrace : 我在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>
The crash happens after handling an SelectionDidChange
on an NSOutlineView
which does a fair amount of processing. 在处理NSOutlineView
上的SelectionDidChange
之后,会发生崩溃,该处理会进行大量处理。
It's hard to pin point what exactly is causing this crash. 很难确定到底是什么导致了崩溃。
Any ideas ? 有任何想法吗 ?
The error was caused by, C#
objects being wrongly garbaged collected . 该错误是由于C#
对象被错误地垃圾回收引起的 。
They were garbage collected because those objects were being returned to objective-c
code (native code), and since no reference was kept in the C#
the garbage collector was deleting them. 之所以将它们作为垃圾回收是因为这些对象将返回到objective-c
代码(本机代码),并且由于C#
没有保留引用,因此垃圾回收器正在删除它们。
This was what was happening : 这就是正在发生的事情:
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
What you should do : 您应该做什么:
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
And that's it ! 就是这样!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.