Title: App is crashing with EXC_BAD_ACCESS on background
Tags: iphone;objective-c;xcode;exc-bad-access
Question: i setted ```NSString *oldChat``` in the header file like this:

```@interface CTFChatViewController : UIViewController {
    NSString *oldChat;
}
- (void)updateChat;
@property (nonatomic, retain) NSString *oldChat;

@end
```

and then i used it:

```- (void)updateChat
{
    NSString *chat = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://theshay.byethost7.com/chat.php"] encoding:NSUTF8StringEncoding error:nil];
    if (![chat isEqual:oldChat]) 
    {
        [webView loadHTMLString:chat baseURL:nil];
        oldChat = chat;
    }

    [self performSelectorInBackground:@selector(updateChat) withObject:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    NSString *chat = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://theshay.byethost7.com/chat.php"] encoding:NSUTF8StringEncoding error:nil];
    oldChat = chat;
    [webView loadHTMLString:chat baseURL:nil];

    [self performSelectorInBackground:@selector(updateChat) withObject:nil];
}
```

App crashed on ```if (![chat isEqual:oldChat])``` with ```EXC_BAD_ACCESS``` error.
why it crashed ?

(XCode 4.5.2, iPhone Simulator 6.0, Base SDK 6.0)

Comment: why are you making property of oldChat, if you are not going to use it?

Here is the accepted answer: oldChat is ```autorelease``` object. Retain it and use  isEqualToString for string comparison.   

``` NSString *chat = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://theshay.byethost7.com/chat.php"] encoding:NSUTF8StringEncoding error:nil];
 oldChat = chat;
[oldChat retain];
```

Comment for this answer: do not forget to release oldChat in dealloc.

Here is another answer: You have to check your NSString is equal or not using isEqualToString: method. Your code should be like this 

```if (![chat isEqualToString:oldChat]){
    //Do something
}
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:02/22/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<iphone><objective-c><xcode><exc-bad-access>', 'Title': 'App is crashing with EXC_BAD_ACCESS on background', 'ViewCount': 441, 'id': 15024055, 'user_AboutMe': "<p><strong>I am 13 years old.</strong></p>\n\n<p>I started programming about 4 years ago, by getting interested in DOS and Linux Operation Systems. I wanted to learn more and more, so I started in learning <code>PHP</code> from site in my native language.</p>\n\n<p>I started programming in <code>Objective-C</code> because my dad's friend bought an brand new iPhone (It was 3 years ago, when iPhone 4 was the newest and the best phone the world ever saw and wasn't papular in my country) So, I buyed an iPhone too, and falled in love with apple. An year after that, I bought a mac (the cheapest mac mini), an book about programming in Objective-C and started programming.</p>\n\n<p>I read over ten books about programming, nine about <code>Objective-C</code> and <code>Cocoa-Touch</code> and one about android (<code>Java</code>) programming.</p>\n", 'user_AccountId': 1083273.0, 'user_DisplayName': 'theShay', 'user_Reputation': 247.0, 'user_Views': 75.0, 'user_id': 1079647.0}}