Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我试图释放类的对象时,ASIHTTP请求不起作用,应用程序正在崩溃_Ios_Ios4 - Fatal编程技术网

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