gpt4 book ai didi

c# - Xamarin.Mac 模糊 SIGSEGV

转载 作者:行者123 更新时间:2023-12-03 17:11:12 25 4
gpt4 key购买 nike

我在 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# 引起的对象被错误地垃圾收集

它们被垃圾收集,因为这些对象被返回到 objective-c代码( native 代码),并且由于 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

就是这样!

关于c# - Xamarin.Mac 模糊 SIGSEGV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com