EXC_BAD_ACCESS, but not when using breakpoints

2019-08-12 06:14发布

问题:

I am getting a crash on my app. It's occurring on dismissModalViewControllerAnimated: message, but... if I set a breakpoint on the NSLog, and step over, it goes through with problem, the EXC_BAD_ACCESS code is 2 and address 0x4:

Thread 1: EXC_BAD_ACCESS(code=2, address=0x4)

I've never had something work with breakpoints and EXC_BAD_ACCESS without them, any ideas?

Please note that my appController is fine. (not released anywhere).

if (appController.modalViewController) {
    NSLog(@"==== RETAIN COUNT ====> %d", appController.modalViewController.retainCount);

    [appController.modalViewController dismissModalViewControllerAnimated:NO];
}

Retain count logs to 1

This also ONLY happens for iOS 4.2 and my app is running on iPad only

回答1:

retainCount is useless. Don't call it.

If you have a crash, you have a backtrace. Please post it.


I've never had something work with breakpoints and EXC_BAD_ACCESS without them, any ideas?

Generally indicates a race condition; your code is dependent on thread A finishing or not finishing something before thread B hits some particular state. Need the backtrace.