I seem to be having a few exc_bad_access
errors in my app. Here's where it gets weird - when I set NSZombieEnabled = YES
, the errors don't seem to get reproduced. The app works perfectly. This question has been asked before, but my question is more along the lines of why this is happening. I know that traditional objective C objects should be flagged down if the issue lay with them, right? So does this point to the problem lying somewhere else? If so, where? Any help would be much appreciated.

- 1
- 1

- 3,069
- 2
- 30
- 35
-
Which version of Xcode and iOS are you using? – Snips Aug 06 '11 at 23:04
-
Xcode 4 and iOS 3.1.2 is the target – Manish Burman Aug 06 '11 at 23:18
-
Are you asking in the sense of why it is that NSZombies misses the `-release` case? [This is a big guess, but...] I suspect it's a bug in NSZombies, they probably use a proxy for every object, then when the retain count hits zero the proxy lives on as a zombie, then it waits for function calls, but maybe they missed [release] because that's the one function they would have intercepted and treated differently than all the others. – Alex Gosselin Aug 07 '11 at 00:55
2 Answers
NSZombieEnabled exists solely to diagnose a small handful of problems. It actually disables the core way that memory management works within iOS. If this solves your problems, then you are likely sending messages (calling methods) on objects that have already been deallocated.
Be sure to fully understand memory management in iOS and then your problems will be solved (NSZombieEnabled isn't a solution):
http://www.raywenderlich.com/2657/memory-management-in-objective-c-tutorial

- 7,817
- 5
- 39
- 54
-
But if they were already deallocated, then wouldn't it give me a message? – Manish Burman Aug 07 '11 at 01:33
-
If memory for a specific object has been released, it is more than likely already assigned to a new object. Your pointer to the object is now a pointer to a block of memory that is being used for something else. If you try to send a message to this released block of memory - it will crash most all of the time. In Obj-C you can send messages to objects that are nil without a crash, but it is different if the pointer is still pointing to a block of memory. – dtuckernet Aug 07 '11 at 01:37
-
1I'm referring to NSZombieEnabled. If it's set to YES, then that block of memory isn't given away to any other object. Right? So if I message that object, NSZombie should tell me something. My point here is that nothing of the sort happens. Enabling NSZombie seems to make all my errors go away. – Manish Burman Aug 07 '11 at 01:41
-
Have you tried running the application in instruments with the Zombies template? It will certainly tell you there if you send a message to a deallocated object (but not sure about elsewhere). However, in the end, it is still a problem with memory management. I would recommend using Instruments to debug it, and letting us know what you find. – dtuckernet Aug 07 '11 at 01:56
-
+1, thanks for your help. I haven't tried that but I will now. I know its an issue with memory management, and I'm familiar with the memory management guidelines. I just can't image where I'm going wrong here. I even commented out all the release statements. Still getting the same error. – Manish Burman Aug 07 '11 at 01:58
-
1It could be that you aren't retaining an autoreleased object that needs to persist beyond its scope. – dtuckernet Aug 07 '11 at 02:00
-
Good suggestion. Unfortunately autorelease doesn't seem to be the issue either. I appreciate all your help though! Thanks! :P – Manish Burman Aug 07 '11 at 02:14
The problem all along seemed to be with CFMutableBitVector. I wasn't setting a count, and up ended up accessing elements beyond its range. As a result I was getting an EXC_BAD_ACCESS error further down the road. NSZombieEnabled=YES for some reason seems to fix this. Anyway, I corrected the issue.

- 3,069
- 2
- 30
- 35