[英]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.