3

So I am getting this error (picture below). What is happening when I get this error is going through my core data data base and averaging out results based on battery statistics that I have collected. This was working fine until I took a break and then came back, plugged it in and it started getting this error. I have an exception breakpoint, but it is still not showing me anything other than the crash in the image.

Anyone know what i should do?

xcode Version 5.0

Let me know if i can post anything else that can help figure out what is causing this!

This is the error

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
Charlie
  • 222
  • 3
  • 20

3 Answers3

8

For any EXC_BAD_ACCESS errors, you are usually trying to send a message to a released object. The BEST way to track these down is use NSZombieEnabled.

This works by never actually releasing an object, but by wrapping it up as a "zombie" and setting a flag inside it that says it normally would have been released. This way, if you try to access it again, it still know what it was before you made the error, and with this little bit of information, you can usually backtrack to see what the issue was.

It especially helps in background threads when the Debugger sometimes craps out on any useful information.

VERY IMPORTANT TO NOTE however, is that you need to 100% make sure this is only in your debug code and not any code you are testing outside of XCode. Because nothing is ever released, your app will leak and leak and leak. To remind me to do this, I put this log in my appdelegate:

if (getenv("NSZombieEnabled"))
  NSLog(@"NSZombieEnabled!");

If you need help finding the exact line, Build-and-Run. When the app crashes, the debugger will show you exactly which line and in combination with NSZombieEnabled, you should be able to find out exactly why and what type of object is being accessed after being released.

coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • ![enter image description here][2][2]: http://i.stack.imgur.com/VsUPb.png @coneybeare I can not do a build and debug however in the build and run i got this (see image). So i just have to figure out what line is memory allocation the address is and that what is going wrong? – Charlie Jan 03 '14 at 22:08
  • Your message was sent to a deallocated instance, so use zombies as I have shown you above. Xcode is very capable of doing a build and debug, so I am not sure what you are talking about. – coneybeare Jan 03 '14 at 23:05
  • If using Xcode 5, Build and Debug is on all the time if breakpoints are activated. That may be the source of your confusion. – coneybeare Jan 03 '14 at 23:58
  • (CMD-Y) only deactivates break point. I also can not find an option to build and debug. – Charlie Jan 04 '14 at 00:01
  • It seems you are missing the important part of my answer. The Zombies are what you need to focus on right now. – coneybeare Jan 04 '14 at 00:02
  • Ahh yes that would be my confusion. the link i posted in my first comment is where it break points to. It is not code i have written. – Charlie Jan 04 '14 at 00:07
  • You can still run the binary with zombies enabled. – coneybeare Jan 04 '14 at 00:09
  • To be honest I have no idea what you are asking me to do. This is definitely me who is not getting it. I am still new to most of this sorry. So i have set up zombies and in my app delegate I am getting the log of NSZombieEnabled!. So it is definily working. I run my app i click the button that makes the code crash and it breakpoints on the place i have that second picture(i.stack.imgur.com/VsUPb.png) from my first comment is where i am stuck on what to do. – Charlie Jan 04 '14 at 01:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44468/discussion-between-coneybeare-and-charlie) – coneybeare Jan 04 '14 at 03:34
0

Sometimes a quick fix is to delete your app from the device and run it again. If this works it means you changed your core data model or something similar.

user2387149
  • 1,219
  • 16
  • 28
  • I tried that but it did not work. I though you normally get an error message when you try to run with a changed database that says something changed within the data base – Charlie Jan 04 '14 at 17:08
0

This happened for me when, I was calling a createMessage function from my Firebase worker and returning the Firebase Document as a whole. The firebase document shouldnt be returned as a whole, that is bad coding practice, instead, you should take the document and parse it and get what you need from it down to the basic types and then return that. Hopefully this helps anyone that might run into this in the future.

amirkrd
  • 203
  • 3
  • 8