开发者

ASIHTTP Request is not working and application is crashing when i tried to release the Object of my Class

开发者 https://www.devze.com 2023-04-06 06:33 出处:网络
In my Main class i am creating an object of my AlbumFetcher class and calling some functions and relasing the object .

In my Main class i am creating an object of my AlbumFetcher class and calling some functions and relasing the object .

AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init];
[_albumFetcher getData];
[_albumFetcher release];

When i relaesed the object after calling some functions , ASIHTTP request finish method is not calling and application is cra开发者_JS百科shing . But when i am not releasing the object everything is working perfect . What i have to do

AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init];
[_albumFetcher getData];
//[_albumFetcher release]; // now ASIHTTP Request n everything is working fine .....

In AlbumFetcher Class i have this functions ...

-(void)getData{

    _fullsizeURL = [NSURL URLWithString:@"http://mysite.com/site/alb_iphone"];        

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:_fullsizeURL];
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(albumrequestDone:)];
    [request setDidFailSelector:@selector(albumrequestFailed:)];
    [request startAsynchronous];
}
- (void)albumrequestDone:(ASIHTTPRequest *)request{
    // here my code
}
- (void)albumrequestFailed:(ASIHTTPRequest *)request{
    // here my code    
}

So where i am going wrong and where i have to release the object .


In your case, ASIHTTPRequest works asynchronously, i.e. in another thread. So your request is not done after [_albumFetcher getData] finishes.

Your request is not finished until albumrequestDone:request or albumrequestFailed:request finished. My suggestion is put [self release] at the end of those two functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消