views:

311

answers:

4

I added NSZombieEnabled to my executable's environment in order to track down an object that I'm over releasing. What I'm finding now, is that a part of my app is crashing that never has crashed before, only when NSZombieEnabled is toggled on. The moment I disable it, no crash occurs.

I need to do forensics on my code, but what can this possibly imply? NSZombieEnabled keeps objects around that are being sent the release message. This might be causing me to crash, but should it?

Also, setting the breakpoint -[_NSZombie methodSignatureForSelector:] doesn't really give me an elaborate enough stack trace to know what's going on.

+2  A: 

If your app crashes with NSZombieEnabled, there's a good chance it crashes with it disabled, just not as soon and not as obviously.

NSZombieEnabled keeps objects around that are being sent the release message. This might be causing me to crash, but should it?

No, it doesn't cause you to crash. What causes you to crash is sending too many release messages to an object. That's what NSZombieEnabled is for.

Also, setting the breakpoint -[_NSZombie methodSignatureForSelector:] doesn't really give me an elaborate enough stack trace to know what's going on.

Try using the ObjectAlloc preset in Instruments.

Peter Hosey
A: 

NSZombie is not supported on iPhone devices. It might work in the Simulator, but not on the device itself.

jbrennan
Uh - yes it is. I use it all the time, on the device, via xCode debugs. Works fine.
Chaos
Alright. I was ill-informed. My bad.
jbrennan
All good - no hard feelings. Just so happened to be using it right at the time I read your post :)
Chaos
+1  A: 

Under NSZombieEnabled, objects are not fully released, they just become zombies. This means that memory can accumulate while you run, particularly in loops where you might be generating a bunch of NSStrings or the like. Your application may be getting killed due to memory usage.

I made the mistake of turning this on and forgetting about it, then spent the longest time trying to figure out why my memory usage kept increasing when I didn't have any obvious leaks.

Brad Larson
+1  A: 

One possibility: It could be that you're accessing an object through an invalid pointer and lucking out that another compatible object happens to be placed there. In that case, NSZombie would prevent the object from being replaced by something compatible and instead put a Zombie in its place.

Chuck