Ios 当我试图释放类的对象时,ASIHTTP请求不起作用,应用程序正在崩溃
在我的主类中,我正在创建我的Ios 当我试图释放类的对象时,ASIHTTP请求不起作用,应用程序正在崩溃,ios,ios4,Ios,Ios4,在我的主类中,我正在创建我的AlbumFetcher类的一个对象,并调用一些函数并重新发布该对象 AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init]; [_albumFetcher getData]; [_albumFetcher release]; 当我在调用一些函数后重新设置对象时,ASIHTTP请求完成方法没有调用,应用程序正在崩溃。但当我不释放这个物体时,一切都很完美。我该怎么办 AlbumFetcher *_albumF
AlbumFetcher
类的一个对象,并调用一些函数并重新发布该对象
AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init];
[_albumFetcher getData];
[_albumFetcher release];
当我在调用一些函数后重新设置对象时,ASIHTTP请求完成方法没有调用,应用程序正在崩溃。但当我不释放这个物体时,一切都很完美。我该怎么办
AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init];
[_albumFetcher getData];
//[_albumFetcher release]; // now ASIHTTP Request n everything is working fine .....
在AlbumFetcher类中,我有以下函数
-(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
}
因此,在哪里出错以及在哪里必须释放对象。在您的情况下,
ASIHTTPRequest
异步工作,即在另一个线程中。因此,您的请求在[\u albumFetcher getData]
完成后不会完成
AlbumFetcher *_albumFetcher = [[AlbumFetcher alloc] init];
[_albumFetcher getData];
[_albumFetcher release];
直到
albumrequestDone:request
或albumrequestFailed:request
完成,您的请求才会完成。我的建议是把[self release]
放在这两个函数的末尾。或者使用AlbumFetcher*\u AlbumFetcher=[[AlbumFetcher alloc]init]autorelease];或者让您的AlbumFetcher dealloc
方法取消并清理ASIHTTPRequest