Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app runs as debug, but crashes as release

I have a program which runs fine on the device in Debug configuration, but fails as a Release. Anyone have this experience, and how do I fix it?

Thx

like image 515
John Smith Avatar asked Jul 25 '10 04:07

John Smith


People also ask

What is one reason a program might work in debug mode but crash in release mode?

Some application examples might work in debug mode but not in release mode. This means that when you reset the microcontroller and try to run without a debugger connected, the application code might not execute as expected. This might be due to certain debug specific options being used in the application project.


1 Answers

I ran into the same problem - App worked fine on simulator and device in Debug mode, but neither in Release mode (it would install, but just display the splashscreen)

  • Xcode 4.3.2
  • iOS Deployment Target 4.3

I kept seeing answers on StackOverflow that said this was a memory management issue, but that didn't make any sense to me since the debug version worked perfectly fine when loaded to my iPhone 4S. I also checked Build Settings to see what differed between the two modes, and I skipped over the one difference that mattered in the end - compiler optimization.

In Build Settings -> under Apple LLVM compiler 3.1 code generation -> Optimization Level, change the Release setting from the default Fastest, Smallest [-Os] to None[-O0] . Fixed my issue.

Found that solution in this blog post: http://www.mindjuice.net/2011/11/30/how-to-fix-an-app-that-crashes-in-release-but-not-debug/.

The Apple Documentation helps, but doesn't explain why doing just the opposite fixes things:

Code optimizations of any kind result in slower build times because of the extra work involved in the optimization process. If your code is changing, as it does during the development cycle, you do not want optimizations enabled. As you near the end of your development cycle, though, the release build configuration can give you an indication of the size of your finished product, so the Fastest, Smallest option is appropriate.

None: The compiler does not attempt to optimize code. Use this option during development when you are focused on solving logic errors and need a fast compile time. Do not use this option for shipping your executable.

Fastest, Smallest: The compiler performs all optimizations that do not typically increase code size. This is the preferred option for shipping code because it gives your executable a smaller memory footprint.

like image 139
an yu Avatar answered Sep 27 '22 17:09

an yu