I have been getting errors while NSURLConnection delegate method connectionDidFinishLoading executes. Interestingly it works on simulator but it crashes on physical device. More interestingly it crashes only when this sequence of operation is done,
- Run App
- Shows Tweet! (Awesome)
- Press Home button
- Double click Home button
- Force quit app
- Again open app
- CRASHED!!!!! ( 🙁 )…Keep crashing until you restart your phone!
ERROR LOG :
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xa0000008
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x321befbc 0x321bb000 + 16316
1 Tittle-Tattle 0x0002cf10 -[MapViewController connectionDidFinishLoading:] (MapViewController.m:108)
2 Foundation 0x3316bc32 0x330a5000 + 814130
3 Foundation 0x330c36e2 0x330a5000 + 124642
4 Foundation 0x330c36ac 0x330a5000 + 124588
5 Foundation 0x330c35ce 0x330a5000 + 124366
6 CFNetwork 0x35e7689e 0x35e67000 + 63646
7 CFNetwork 0x35e6b53e 0x35e67000 + 17726
8 CFNetwork 0x35e6b632 0x35e67000 + 17970
9 CFNetwork 0x35e6b23c 0x35e67000 + 16956
10 CFNetwork 0x35e6b172 0x35e67000 + 16754
11 CoreFoundation 0x34176afc 0x340e9000 + 580348
12 CoreFoundation 0x341762c8 0x340e9000 + 578248
13 CoreFoundation 0x3417506e 0x340e9000 + 573550
14 CoreFoundation 0x340f84d6 0x340e9000 + 62678
15 CoreFoundation 0x340f839e 0x340e9000 + 62366
16 GraphicsServices 0x3254dfc6 0x3254a000 + 16326
17 UIKit 0x3734e73c 0x3731d000 + 202556
18 Tittle-Tattle 0x000200e0 main (main.m:16)
19 Tittle-Tattle 0x00020084 start + 32
CODE :
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[urlConnection cancel];
[urlConnection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//Since we got new fresh data we shall put it in LatestLocationData entity in CoreData
[self insertLastKnownLocationDataIntoCoreDataWith:responseString];
//Test purpose only, See what we have got in CoreData
[self fetchLastKnownLocationDataFromCoreData];
NSDictionary *results = [responseString JSONValue];
placesNearBy = [results objectForKey:@"results"];
[responseString release];
[self dropNearByPlacesAnnotationsFrom:placesNearBy];
}
Question : What could be the possible reason for this?
Similar Question(Not by me!) previously asked but no one replied on that question : Application not running in iOS 5
My understanding so far is, EXE_BAD_ACCESS only happens when you try to access memory address which hasn’t been allocated, Or previously allocated but now it’s been released.
EDIT AFTER RESPONSE IN COMMENT :
Hey Firoze, This is how I am init NSURLConnection
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Looking at your comments I would suggest you use
@propertydeclarations for all of your ivars. They will alleviate all of the manual memory management you are having to do, which is probably where your problem lies.Quick example
YourClass.h
YourClass.m