【问题标题】:Xamarin.Mac obscure SIGSEGVXamarin.Mac 模糊 SIGSEGV
【发布时间】:2014-10-21 20:06:12
【问题描述】:

我遇到了 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 后发生崩溃。

很难确定究竟是什么导致了这次崩溃。

有什么想法吗?

【问题讨论】:

    标签: c# macos cocoa xamarin xamarin.mac


    【解决方案1】:

    错误是由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

    就是这样!

    【讨论】:

      猜你喜欢
      • 2017-09-01
      • 1970-01-01
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多