0

I've read on here that NSZombies with ARC enabled can actually cause a crash and I've also read it can't be the cause of a crash. People have said it can cause a crash by a bug where dealloc is not called on the object. Is that true and is that still the case? I realize it could crash by running out of memory but is that the only time a crash could result from zombies being enabled?

The post I'm looking at is: NSZombie crashing app when enabled on the iPhone

Community
  • 1
  • 1
SukyaMaki
  • 173
  • 1
  • 1
  • 5
  • See also http://stackoverflow.com/questions/4168327/what-is-nszombie – matt Mar 20 '14 at 15:43
  • 1
    What do you want to know that the other question doesn't already tell you? – Tim Mar 20 '14 at 15:44
  • 1
    well you generally only have zombies on when you are looking for the cause of a crash already... so do you think zombies is causing a crash before the crash you are looking for? it is probably just catching one that could be a crash before hand... like a pointer that gets assigned to another object that happens to respond to the selector you are sending it... like -description -length, -intValue, something common probably – Grady Player Mar 20 '14 at 15:47

2 Answers2

2

It is not clear what you are asking.

By NSZombies, do you mean setting the NSZombies flag to true in your project? Yes, that will cause your program's memory to grow forever, and you will eventually run out of memory and crash. (When zombies are enabled, instead of releasing objects on dealloc, the runtime marks them as zombies and leaves their memory in use.)

If you mean can having zombies in your program (objects that get deallocated but your code tries to send messages to them) then yes, that can, and often does, cause crashes. Zombies are less common under ARC, but still possible.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Yes, I mean't "If you mean can having zombies in your program (objects that get deallocated but your code tries to send messages to them)". But the root cause of the crash wouldn't be because NSZombies were enabled, right? Meaning turning off NSZombies would not have prevented the crash. – SukyaMaki Mar 20 '14 at 15:58
  • @SukyaMaki You are confusing **zombies** and the `NSZombieEnabled` debugging mechanism. "Zombies" are just plain objects that are messaged after deallocation. You can't turn them off. – Nikolai Ruhe Mar 20 '14 at 16:03
0

Setting NSZombieEnabled does not cause a crash by itself.

Of course some otherwise hidden error in your app can show up as a side effect of the changes in memory usage.

People have said it can cause a crash by a bug where dealloc is not called on the object.

That is not the case. Enabling zombie detection does not prevent dealloc from being called.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200