I have the following code, from which I am getting an EXC_BAD_ACCESS error:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(responseString);
}
The weird thing is, the bad access error is actually coming from the NSLog() line, when it tries to access responseString. I’ve even tried adding a retain or autorelease to the first line, but I still get the error.
Any thoughts on what might be happening? To my knowledge, there shouldn’t be any issue, because I’m calling it immediately after it’s defined, so responseString should not have been released yet, correct?
EDIT: I should mention, receivedData is an NSMutableData object.
Try
Your
responseStringmight have some ‘reserved sequences’, like%@or%d.The former will cause
NSLogto access ‘object’ in arbitrary location in memory, since it doesn’t know (or doesn’t care) how many parameters you actually provided.