views:

122

answers:

3

Is there any danger in compiling an application for distribution with NSZombie still enabled? I generally leave it turned on for all of my apps while developing because of how useful it is, but I don't understand the full ramifications and potential issues related to enabling it and leaving it on indefinitely.

Thanks!

+3  A: 

If you leave it on, your application will not release all the memory used, so over time, your application will use up all the RAM on the device and be killed by the OS.

Why would you leave it on if you aren't actually looking for for a memory leak?

Jay
I generally find it easier to debug and develop while just leaving it on. Thanks for the information that avoided what could have been an unknowingly annoying bug in the future! I just assumed it would only be applicable to debugging builds if it was that dangerous.
mjdth
Yes, make sure you keep track of this. I accidentally left this on and nearly tore my hair out trying to figure out why what looked like clean code was using up memory like crazy.
Brad Larson
Zombies have nothing to do with memory leaks. Zombie objects have been released and don't exist. Leaks are objects that exist but nobody knows about them.
David Dunham
It's true that the zombies aren't actual leaks, but they do chew up memory like them. From the CocoaDev wiki ( http://www.cocoadev.com/index.pl?NSZombieEnabled ): "NSZombieEnabled should not be left in place permanently, as by default no objects will ever be truly deallocated, making your application use tremendous amounts of memory." During debugging, this can make it hard to find actual leaks.
Brad Larson
+3  A: 

Absolutely. With NSZombie, no memory can be freed, ever. Deallocated objects just turn into zombies. Eventually, after your pile of zombies gets big enough, your app will crash from memory exhaustion.

Chuck
+2  A: 

It's not a compile option. It's an environment variable. There is no danger leaving it on, because it is not part of the application bundle you will release.

It does make it impossible to find leaks, so you might not want to leave it enabled.

David Dunham
THIS appears to be the correct answer. The environment variables set in Xcode only affect apps launched by Xcode or Instruments. They're not present otherwise. Try it out: NSLog(@"NSZombieEnabled: %s", getenv("NSZombieEnabled"));
nschum