1

我遇到了一个模糊的段错误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>

崩溃发生在处理一个进行大量处理的SelectionDidChangeon之后NSOutlineView

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

有任何想法吗 ?

4

1 回答 1

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

就是这样!

于 2014-10-22T10:20:34.863 回答