0
NSArray *listItems = [temp componentsSeparatedByString:@","];

Can anyone please tell me why?

temp is an NSString

Here's the entire code

- (NSString *)getStreetAddress
{
    NSString* temp = [addressArray objectAtIndex:0];
    if (temp != nil) {
        NSArray *listItems = [temp componentsSeparatedByString:@","];
        temp = [listItems objectAtIndex:0];
   }
    return temp;
}

EXC_BAD_ACCESS is the error

Cocoa Dev
  • 9,361
  • 31
  • 109
  • 177

1 Answers1

2

If execution gets to the line you say, en the most likely problem is that the first item in addressArray has been improperly deallocated while still part of the array. Since the array doesn't check to make sure the object it contains is valid, it will return a pointer to free memory. When you try to access this memory, it crashes. You can try running with NSZombiesEnabled=YES in the environment. If I am correct, you will get a error message logged to the console.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • addressArray is a property and isn't it suppose 2 act like a global variable for the class? – Cocoa Dev Apr 21 '11 at 22:00
  • A property is only accessible through that instance of the class, not the class itself. The problem isn't that the array has been released, but that something *inside* the array has been released. – ughoavgfhw Apr 21 '11 at 22:05
  • Thanks but how can I look inside the array or prevent it from being released? – Cocoa Dev Apr 25 '11 at 13:01
  • If you use NSZombies, as I mentioned in my answer, you will get a log when you try to use the object which will tell you what type of object it is, and possibly some of the information the object contained. You should check the locations where you create or modify the array and look for something that was released or autoreleased too many times. You could also use the Build & Analyze option. The analyzer is pretty good at finding improper memory management. – ughoavgfhw Apr 26 '11 at 02:09
  • See http://stackoverflow.com/questions/2190227/how-do-i-set-nszombieenabled-in-xcode-4 – ughoavgfhw May 03 '11 at 20:11