Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS crash only when NOT running via XCode. Concidence?

My app was crashing only when not running using XCode debugger. It was hard to track because I can't debug but I finally figured it out. It was because of calling release on some object not owned by me. Before I corrected it I searched and found 2 related questions here (links below)

iOS App Crashes when running by itself on device, does not crash when running through Xcode using debugger, or in simulator

iPhone crash only when device not connected to xcode, how to understand the crash log?

None of the above question has answered why no crash when running via debugger.So my question is why it happens ? I know reasons for debug/release specific crashes but this is crazy. Is it just by chance although it happened more than 10 times.

like image 951
msk Avatar asked Mar 29 '12 18:03

msk


3 Answers

I had this same issue while working on a project modularised with Xcode Frameworks. Even after removing all the logic in AppDelegate and only returning true inside application:didFinishLaunchingWithOptions, I was still getting the crash. Then I switched to my project settings, in the Frameworks, Libraries, and Embedded Content section and changed the embed option for the frameworks I added to Embed & Sign. This was what fixed the issue for me. I hope someone finds this helpful.

like image 150
Oluwatobi Omotayo Avatar answered Oct 20 '22 20:10

Oluwatobi Omotayo


What you describe is not atypical of obscure memory-related bugs. You might also want to use debug-malloc at such times. Although that is not guaranteed to find everything. The reason (and it's been happening probably as long as there've been source-level debuggers) is that memory is laid out at least somewhat differently in debuggable code, and when running under the debugger. So the error results in a different piece of memory being (harmlessly) corrupted when under the debugger. When not under the debugger the location corrupted is actually something that your code cares about, and it crashes.

The same could happen in reverse, but you'd never know - if it crashes when run debuggable, you'd find it before switching to running outside the debugging environment.

like image 3
DRVic Avatar answered Nov 03 '22 20:11

DRVic


Reiterating @jyoung's answer since I didn't see it the first time I glanced through:

Try running with Zombie Objects turned off.

In debug mode if you have it turned on it is handling memory allocation differently. Try running it without.

Go to Edit Scheme... > Run > Diagnostics. Then make sure zombie objects is turned off:

enter image description here

Then run through your code path again.

like image 2
RyanJM Avatar answered Nov 03 '22 20:11

RyanJM