ASIHTTPRequest, EXC_BAD_ACCESS when request did finished

后端 未结 3 1214
后悔当初
后悔当初 2021-01-14 12:58

I\'m trying to do an asynchronous request with ASIHTTPRequest, but have some problem getting notified when the request is done.

-(void)doDownload{
    NSURL          


        
相关标签:
3条回答
  • 2021-01-14 13:28

    [request responseString];

    Check retainCount of request before this call. Propably it equals zero :) If that - you shouldn't forget to retain it when you creates it in doDownload method.

    0 讨论(0)
  • 2021-01-14 13:37

    Following line of your code seems to be wrong.

    [request setDidFinishSelector:@selector(requestFinished)];
    

    requestFinished method has an argument (ASIHTTPRequest *).
    Therefore you should add ":", when you set a selector like as follows.

    [request setDidFinishSelector:@selector(requestFinished:)];
    
    0 讨论(0)
  • 2021-01-14 13:46

    Are you sure that your class that implements - (void)requestFinished:(ASIHTTPRequest *)request is still there when the request finishes? It looks to me like the class gets deallocated too early. Note that the delegate property does not retain its content.

    You could add a [self retain] to doDownload and a [self release] to - (void)requestFinished:(ASIHTTPRequest *)request, but make sure (!) that [self release] doesn't get called too often. This is also a possible memory leak if a request would never finish. It would be best to retain your class somewhere else.

    You might also try to debug with NSZombieEnabled set to YES to find the error.

    0 讨论(0)
提交回复
热议问题