I have a line of code that is cause a ‘EXC_BAD_ACCESS’ error. The line of code is as follows (formatted into one line and nested code removed for ease of reading).
if (![sendData isEqualToString:@'-']){ ... }
The actual error occurs on the IF line. the odd thing is that if I put a breakpoint on that line, the NSString called sendData (shown as NSCFString with a value of ‘-‘ without the quotes). Why would this be causing an error?
To catch this problem you’ll have to put break points in all callback methods.
The problem is simple, the code is trying to access memory it cant find.
Finding that line of code is harder because the callbacks are not called sequentially.
Output form the console:
The problem occurs some where in or after
ProcessDatawhich is a callback I think. Try and put a break point around line 157 in TwoViewAppAppDelegate.mIt’s not that line that is causing the
EXC_BAD_ACCESSif you add:To the if() statement you can see it passes over the
if ( ![sendData isEqualToString:@'-'] ){...}The error occurs when you return form the method call.
Ok form you comments this might help:
If you create strings using
@'My string'the compiler will map these to he same memory if they have the same content, i.e.:Will all point at the same memory space.
This may help, but I’m not sure how? Maybe you can post more code so I can run it on my set up.
Remember an auto release pool is created at the start of the event cycle on the iPhone.
Therefore it is a good idea to call autorelease on sendData as soon as you assign it to the ivar.