问题
When I push a certain view controller, then go pop it and then repeat a seemingly random number of times the app eventually crashes with the error EXC_BAD_ACCESS.
This I can reliably replicate EVERY TIME. It happens mostly the second time I pop the view controller, but sometimes it can be the third or fourth.
So I decided to set NSZombieEnabled to see what the problem was.
But with this enabled the crash can't be replicated. All thats changed is I check the box next to "NSZombieEnabled" in my active executable's config and the app works perfectly.
Any ideas what is causing this?
Thanks
回答1:
I had this same problem with an iPhone app in simulator. It would throw an EXC_BAD_ACCESS when I popped a particular view controller but as soon as NSZombieEnabled was on, the error vanished.
To narrow it down, I commented out all the releases in the popped view controller's dealloc, which kept the app from crashing, and then uncommented them one at a time until it crashed again, revealing the offending variable.
In my case, it was actually the variable's release statement itself that was throwing the EXC_BAD_ACCESS
I can't tell you exactly how to fix it from there other than to not release. I was able to get it working fine after tweaking and cleaning the code but when I try to roll back the changes to get the error again and narrow down the precise fix, I was unable to replicate the problem. I actually got it on the first roll back but never again. Maybe there's something environmental at work?
This isn't an answer exactly but maybe it'll point someone in the right direction.
来源:https://stackoverflow.com/questions/4164233/nszombieenabled-fixes-my-app