在解除分配DetailViewController
时,无法在iOS 11设备上复制崩溃。
该应用的DetailViewController
继承自BaseViewController
。 DetailViewController
具有DetailViewModel
属性。
DetailViewController
,BaseViewController
和DetailViewModel
都是用Objective-C编写的。我将Swift版本升级到Swift 4
并向DetailViewModel
添加了Swift扩展。
@objc extension DetailViewModel {
func foo() {
let conclusionBlock: (() -> Void) = { [weak self] in
guard let strongSelf = self else { return }
strongSelf.viewController.reloadData()
}
let viewModel = OtherViewModel(conclusionBlock: conclusionBlock)
let otherViewController = OtherViewController.make(viewModel: viewModel)
let nav = UINavigationController(rootViewController: otherViewController)
nav.modalPresentationStyle = .fullScreen
viewController.present(nav, animated: true, completion: nil)
}
}
查看日志,func foo()
swift扩展程序中的DetailViewModel
未被调用,并且仍然在dealloc上崩溃。
有没有人知道问题是什么或如何解决?
谢谢
堆栈跟踪:
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x18589d7f4 objc_object::release() + 16
1 CoreFoundation 0x1862f3108 cow_cleanup + 112
2 CoreFoundation 0x18623a51c -[__NSArrayM dealloc] + 68
3 libobjc.A.dylib 0x18587eef4 object_cxxDestructFromClass(objc_object*, objc_class*) + 148
4 libobjc.A.dylib 0x18588c638 objc_destructInstance + 88
5 libobjc.A.dylib 0x18588c690 object_dispose + 16
6 AppName 0x100c7dbec -[DetailViewModel .cxx_destruct] (DetailViewModel.m:43)
7 libobjc.A.dylib 0x18587eef4 object_cxxDestructFromClass(objc_object*, objc_class*) + 148
8 libobjc.A.dylib 0x18588c638 objc_destructInstance + 88
9 libobjc.A.dylib 0x18588c690 object_dispose + 16
10 AppName 0x100cbe358 -[DetailViewController .cxx_destruct] (DetailViewController.m:103)
11 libobjc.A.dylib 0x18587eef4 object_cxxDestructFromClass(objc_object*, objc_class*) + 148
12 libobjc.A.dylib 0x18588c638 objc_destructInstance + 88
13 libobjc.A.dylib 0x18588c690 object_dispose + 16
14 UIKit 0x18fb338f4 -[UIResponder dealloc] + 156
15 UIKit 0x18f8e9e7c -[UIViewController dealloc] + 1776
16 AppName 0x100c9b66c -[BaseViewController dealloc] (BaseViewController.m:56)
17 AppName 0x100cb6570 -[DetailViewController dealloc] (DetailViewController.m:261)
18 UIKit 0x18f9d3ec4 __destroy_helper_block_.150 + 80
19 libsystem_blocks.dylib 0x185d91a60 _Block_release + 160
20 UIKit 0x18fa5f5bc -[UIViewAnimationBlockDelegate .cxx_destruct] + 72
21 libobjc.A.dylib 0x18587eef4 object_cxxDestructFromClass(objc_object*, objc_class*) + 148
22 libobjc.A.dylib 0x18588c638 objc_destructInstance + 88
23 libobjc.A.dylib 0x18588c690 object_dispose + 16
24 CoreFoundation 0x18623d998 -[__NSDictionaryI dealloc] + 136
25 libobjc.A.dylib 0x18589e138 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 836
26 CoreFoundation 0x186232050 _CFAutoreleasePoolPop + 28
27 CoreFoundation 0x186311b04 __CFRunLoopRun + 2020
28 CoreFoundation 0x1862322d8 CFRunLoopRunSpecific + 436
29 GraphicsServices 0x1880c3f84 GSEventRunModal + 100
30 UIKit 0x18f7df880 UIApplicationMain + 208
31 AppName 0x100d59540 main (main.m:10)
32 libdyld.dylib 0x185d5656c start + 4
答案 0 :(得分:1)
要帮助复制此问题,请尝试在Xcode 9中启用Address Sanitizer。
答案 1 :(得分:1)
当对象被销毁并释放其数组时,您有一个存储在数组中的对象被过度释放。
您可以先激活zombie objects
(在播放按钮附近显示您的目标,然后选择scheme/Run/Diagnostics/Zombie objects
)。在这种模式下,对象并未真正释放,因此您可以查询导致崩溃的对象以查看其类型并开始跟踪它。