Is it true NSZombies can cause a crash?

114 Views Asked by At

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

2

There are 2 best solutions below

2
Duncan C On

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.

0
Nikolai Ruhe On

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.