Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asihttprequest crashes my app

I have a navigation based app. Press a button on main view, then I push a new view to the navigation controller. All pretty basic stuff.

When the new view is loaded, I do an ASIHTTPRequest to fetch some json data, which is a list of image urls. Then I do a for loop, create a bunch of ASIHTTPRequests, add them to a queue and then run the queue.

But if I click on the back button before the queue is finished, the app crashes, this app displays houses and lets say you pick the wrong house, click back very quickly, before any photo is displayed, bumm crash.

This thread http://groups.google.com/group/asihttprequest/browse_thread/thread/3d4815198aa889b9 explains my problem real well, except I do cancel all requests on view did unload, set delegate to nil and release the queue.

Still I crash. I crash pretty much every time if I use 3G, but on wifi it is real hard to make it crash, but quite doable.

In almost 80% instances the debugger jumps to this line in ASIHTTPRequest.m

(void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders { 
  if ([self error] || [self mainRequest]) { return; }  
--> if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) {

Many many cases it jumps to :

(void)requestReceivedResponseHeaders:(NSMutableDictionary *)newResponseHeaders { 
  if ([self error] || [self mainRequest]) { return; }    
---> if (delegate && [delegate respondsToSelector:didReceiveResponseHeadersSelector]) {  

Ad in a handful of instances it goes to my main loop

int main(int argc, char *argv[]) {  
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
--> int retVal = UIApplicationMain(argc, argv, nil, nil); with SIGBART error [pool release]; return retVal;  

I am using MBP and MacPro, latest OS X, Xcode 4.0.2 and I test on all apple devices except original iPhones.

I really don't want to re-write my whole app, but is there anything else out there that compares with ASIHTTPRequest ?

like image 502
Trausti Thor Avatar asked Apr 18 '11 09:04

Trausti Thor


1 Answers

Try cancelling and unsetting the delegate in -viewWillUnload rather than -viewDidUnload. I suspect the window of time in which it's actually unloading (between calling those two UIViewController methods) is the time period when you're crashable. The delegate has gone away, but you haven't told your ASIHTTPRequest object that yet.

like image 82
Dan Ray Avatar answered Sep 27 '22 18:09

Dan Ray