IOS 11 EXC_BAD_ACCESS KERN_INVALID_ADDRESS on dealloc

Unable to replicate failure on iOS 11 devices when releasing DetailViewController .

The application has a DetailViewController that inherits from BaseViewController . DetailViewController has the DetailViewController property.

DetailViewController , BaseViewController and DetailViewModel are recorded in Objective-C. I upgraded the version of Swift to Swift 4 and added the Swift extension to DetailViewModel .

 @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) } } 

Looking at the logs, the func foo() in DetailViewModel does not call the quick extension and it still falls on dealloc.

Anyone have any ideas as to what the problem is or how to fix it?

thanks

stack trace:

 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 
+5
source share
2 answers

To help replicate the problem, try enabling Address Sanitizer in Xcode 9.

+1
source

You have an object stored in an array that is overfulfilled when the object is destroyed and frees its array.

You can first activate zombie objects (click on your target next to the PLAY button, select scheme/Run/Diagnostics/Zombie objects ). in this mode, the objects are not actually released, so you can query the object that causes the crash to find out what its type is and start tracking it.

+1
source

Source: https://habr.com/ru/post/1273227/


All Articles