我的应用程序有一个大纲视图,可以从服务器频繁更新。每当我收到更新时,我都会重新加载大纲视图。我同时对轮廓进行多项操作,例如在鼠标悬停时显示一些按钮、展开/折叠项目。对于这些操作,我从大纲视图中获取项目NSOutlineView.item(atRow:)
问题是,在随机情况下,我的应用程序在低于 10.12 的操作系统版本上内部调用委托方法EXC_BAD_ACCESS (SIGSEGV)
的区域崩溃。我知道操作系统版本 10.12 中的项目有自己的保留和发布周期,默认设置为。所以崩溃不会发生在 10.12 以上。NSOutlineView
NSTableView
NSOutlineView
stronglyReferencesItems
true
那么我该如何解决这个问题呢?有人可以指导我如何手动保留和释放传递给NSOutlineView
较低版本的项目。
简单地说,我需要在 10.12 以下的版本中启用stronglyReferencesItems
set to的行为。true
注意:正如我上面所说,我会执行复杂的操作,NSOutlineView
例如移动事件、展开/折叠(在某些情况下展开所有项目)、使用服务器频繁更新重新加载列表。所以在这里提到我的代码会很复杂。
以下是供您参考的崩溃日志之一:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x000000010c5cec51 swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::incrementSlow(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 33
1 libswiftCore.dylib 0x000000010c5ab842 _swift_retain_n_(swift::HeapObject*, unsigned int) + 66
2 libswiftCore.dylib 0x000000010c5f7ac8 swift_bridgeObjectRetain_n + 104
3 com.prosoftnet.remotepcSuite 0x000000010bc8c626 RPCHostGroupTableCellView.setupView(group:) (in RemotePCSuite) (RPCHostGroupTableCellView.swift:0)
4 com.prosoftnet.remotepcSuite 0x000000010bd61198 RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (RPCHostListViewController.swift:579)
5 com.prosoftnet.remotepcSuite 0x000000010bd61a10 @objc RPCHostListViewController.outlineView(_:viewFor:item:) (in RemotePCSuite) (<compiler-generated>:0)
6 com.apple.AppKit 0x00007fff8f19e0d0 -[NSTableView(NSTableViewViewBased) makeViewForTableColumn:row:] + 76
7 com.apple.AppKit 0x00007fff8f19d541 -[NSTableRowData _addViewToRowView:atColumn:row:] + 300
8 com.apple.AppKit 0x00007fff8f19d27a -[NSTableRowData _addViewsToRowView:atRow:] + 184
9 com.apple.AppKit 0x00007fff8f19b9ad -[NSTableRowData _initializeRowView:atRow:] + 373
10 com.apple.AppKit 0x00007fff8f19aad2 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 396
11 com.apple.AppKit 0x00007fff8f23a9d1 -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 254
12 com.apple.AppKit 0x00007fff8f23a7a3 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 1856
13 com.apple.AppKit 0x00007fff8f239fc7 -[NSTableRowData updateVisibleRowViews] + 230
14 com.apple.AppKit 0x00007fff8f23fe82 -[NSTableView viewWillDraw] + 178
15 com.apple.AppKit 0x00007fff8f2bd83f -[NSOutlineView viewWillDraw] + 169
16 com.apple.AppKit 0x00007fff8f0e6fa1 -[NSView(NSInternal) _sendViewWillDrawAndRecurse:] + 535
17 com.apple.AppKit 0x00007fff8f058ae1 -[NSView(NSLayerKitGlue) _layoutSublayersOfLayer:] + 142
18 com.apple.QuartzCore 0x00007fff8dd79404 -[CALayer layoutSublayers] + 219
19 com.apple.AppKit 0x00007fff8f058a3c _NSBackingLayerLayoutSublayers + 158
20 com.apple.QuartzCore 0x00007fff8dd78fe8 CA::Layer::layout_if_needed(CA::Transaction*) + 366
21 com.apple.QuartzCore 0x00007fff8dd78e66 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
22 com.apple.QuartzCore 0x00007fff8dd78602 CA::Context::commit_transaction(CA::Transaction*) + 242
23 com.apple.QuartzCore 0x00007fff8dd7839e CA::Transaction::commit() + 390
24 com.apple.QuartzCore 0x00007fff8dd86f09 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 71
25 com.apple.CoreFoundation 0x00007fff99bdaf47 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
26 com.apple.CoreFoundation 0x00007fff99bdaea0 __CFRunLoopDoObservers + 368
27 com.apple.CoreFoundation 0x00007fff99bcca18 CFRunLoopRunSpecific + 328
28 com.apple.HIToolbox 0x00007fff8eb4256f RunCurrentEventLoopInMode + 235
29 com.apple.HIToolbox 0x00007fff8eb422ea ReceiveNextEventCommon + 431
30 com.apple.HIToolbox 0x00007fff8eb4212b _BlockUntilNextEventMatchingListInModeWithFilter + 71
31 com.apple.AppKit 0x00007fff8f08a8ab _DPSNextEvent + 978
32 com.apple.AppKit 0x00007fff8f089e58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
33 com.apple.AppKit 0x00007fff8f07faf3 -[NSApplication run] + 594
34 com.apple.AppKit 0x00007fff8effc244 NSApplicationMain + 1832
35 com.prosoftnet.remotepcSuite 0x000000010bc519a9 main (in RemotePCSuite) (AppDelegate.swift:12)
36 libdyld.dylib 0x00007fff8e4b95c9 start + 1