What does mean? I get this error when trying to iterate through a file in Cocoa obj-c.
I can\'t find any information on the web.
Would appreciate some help.
For other people running into this problem with entirely different code, this is a bit of a red herring.
The warning is from the debugger itself. The debugger creates a struct containing info for each object in the system. After the EXC_BAD_ACCESS, it tried to create one of these but was unable to. Note that this is a warning and not an error so it may even be expected in situations like this.
In any event, the details surrounding this don't matter. You've got to find the source of your EXC_BAD_ACCESS. A common cause is trying to access an object after it has been released.
This line is wrong and should produce a compiler warning:
NSString* string = [[NSString alloc] initWithUTF8String:line];
The method initWithUTF8String:
expects an UTF-8 encoded C string and not a NSString
object.
Before you continue you should fix all compiler warnings! And you also should check that the parts
array actually contains as many objects as you expect. You also need to use a format string with NSLog, you might even crash there if your line contains any %
characters.
I happen to run into EXC_BAD_ACCESS
on a fairly regular basis (which is not a good thing), because we haven't enabled ARC yet.
I find the best way to track those errors down by using the Profiler in Zombie modus. This post shows you how to "hunt for zombies":
How do I set up NSZombieEnabled in Xcode 4?
For someone who comes across this in the future, I got this problem because I was doing this too much:
NSString* aString = @"";
for(int i=0; i<someLargeNumber; i++) {
aString = [aString stringByAppendingFormat:@"..."];
}
Once I switched to using NSMutableString
, the problem was resolved.