Search code examples
iphoneiosobjective-cxcode4.5asihttprequest

Frequently asihttprequest runrequests crash


  • thread #7: tid = 0x2403, 0x351b9010 libsystem_kernel.dylibmach_msg_trap + 20 frame #0: 0x351b9010 libsystem_kernel.dylibmach_msg_trap + 20 frame #1: 0x351b920c libsystem_kernel.dylibmach_msg + 56 frame #2: 0x33672422 CoreFoundationCFRunLoopServiceMachPort + 126 frame #3: 0x3367115a CoreFoundation__CFRunLoopRun + 882 frame #4: 0x335f44dc CoreFoundationCFRunLoopRunSpecific + 300 frame #5: 0x335f43a4 CoreFoundationCFRunLoopRunInMode + 104 frame #6: 0x30e8cbc8 Foundation+[NSURLConnection(Loader) resourceLoadLoop:] + 308 frame #7: 0x30e8ca90 Foundation-[NSThread main] + 72 frame #8: 0x30f205a0 Foundation_NSThread__main + 1048 frame #9: 0x3709bc1c libsystem_c.dylib`_pthread_start + 320

I am not using ASINetworkQueue and using through an array of urls, and I have implemented the requestFinished: method, that gets called fine. I got received crash when request is not responded.

Could you please some one help me out ?

Sample Code snippet :

Class A (Wrapper class extends ASIHTTPRequest) :

ASIHTTPRequest *httpRequest;

- (id)initWithURL:(NSString *)anURL errorInfo:(NSError **)error {
    if (self = [super init]) {
        NSURL *httpURL = [NSURL URLWithString:anURL];
    httpRequest = [self createASIRequest:httpURL];
    didFinishSelector = @selector(requestFinished:);
    didFailSelector = @selector(requestFailed:);
        return self;
    }
}

- (void)dealloc {
    if (httpRequest) {
       [httpRequest clearDelegatesAndCancel];
       [httpRequest release];
       httpRequest = nil;
    }
    [super dealloc];
}

- (ASIHTTPRequest *)createASIRequest:(NSURL *)url {
    ASIHTTPRequest *request = [[ASIHTTPRequest requestWithURL:url] retain];
    request.delegate = self;
    return request;
}

Class B :

Request in loop:

 Class A *d = [[Class A alloc] initWithURL:url errorInfo:&pError];
 d.didFinishSelector = @selector(responseHandler:);
 d.didFailSelector = @selector(responseHandler:);

Solution

  • The delegate methods are being called after view controller has been released. So, needs to clean all delegates before releasing the view controller.This works for me.