iosbackgroundautomatic-ref-countingexc-bad-accessnszombieenabled

Is it possible that NSZombie doesn't point out EXC_BAD_ACCESS with ARC?


i'm currently working on an ios project with some people, one of us decided to use ARC in a part of the app.

Unfotunatly, we are currently experiencing some crashes when coming back from background.

Here are the steps we follow to crash the application, we perform them with the ios-simulator:

  1. start the application
  2. get on a ViewController A (coded with ARC)
  3. get on a ViewController B (not coded with ARC -to be honest i don't know if it's relevant-)
  4. put the application in background.
  5. simulate a memory warning (thx to the simulator)
  6. start again the application, we'll be on the ViewController B
  7. go back on the Viewcontroller A
  8. the application crashes pointing the main function with an EXC_BAD_ACCESS

We did try to use NSZombieEnabled to YES, but when we do it, the application doesn't crash and keeps running perfectly, so we wonder if it might be possible that NSZombieEnabled doesn't work well with ARC?

if anyone could give me a quick and clear insight about ARC and NSZombieEnabled that would be apreciated, i think i know how all of it works, but apparently i must be missing something.

Thanks anyway for your help and time.


Solution

  • Better than using the NSZombieEnabled, you should Profile the project, and use the Zombie instrument. When you do the same thing it should stop and say "zombie messaged", where you can click an arrow to see the class that is a zombie, and where it was allocated/deallocated.

    I don't think the crash has to do with ARC, instead in viewDidUnload you are deallocating something, and then not setting a reference to nil - when you come back it tries to use the invalid reference.

    Probably you would be better off if everything used ARC as it really helps to cure issues like this (the bug is very likely in the non-ARC code).