kern_invalid_address on dealloc

Can't replicate a crash on iOS 11 devices when deallocating the `DetailViewController`.



The app has a `DetailViewController` which inherits from the `BaseViewController`. `DetailViewController` has a `DetailViewModel` property.



`DetailViewController`, `BaseViewController` and `DetailViewModel` are all written in Objective-C. I upgraded the Swift version to `Swift 4` and added a 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, `func foo()` in the `DetailViewModel` swift extension is not called and it's still crashing on dealloc.


Has anyone got ideas as to what's the issue or how to fix it?


Thank you


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

Replies

Did you ever figure this out? I'm trying to track down a similar issue here:

https://github.com/Kochava/kochava-tracker-ios-sdk-cocoapod/issues/7


In the above case, code that works in most development environments does not work in all.