【问题标题】:Leaks in NSURLConnectionNSURLConnection 中的泄漏
【发布时间】:2010-06-22 00:21:04
【问题描述】:

我已经在 Google 上搜索了很多,并阅读了很多关于 NSURLConnection 泄漏问题的信息,但没有一个给出关于解决这些泄漏的解决方案的明确答案。 我创建了一个异步连接,每次建立连接时,都会出现 GeneralBlock-3584 泄漏。有时,负责的库显示为 Foundation [NSThread start] 框架。 GeneralBlock-3584 的某些实例将 CFNetwork HostLookup_Master::HostLookup_Master(__CFString const*, InheritEnum<_extendedhostinfotype cfhostinfotype>, __CFHost*, CFStreamError*) 作为负责框架。 我尝试按照某些人的建议将 NSURLCache 大小设置为 0。但是,即使这样也行不通。

这是我的连接器类的样子:

-(void) connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];

    NSMutableURLRequest *request  = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
    self.delegate = theDelegate; 

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];

    [NSURLConnection connectionWithRequest:request delegate:self];
    [pool release];


}


- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    if(xmlResponse == nil){
        xmlResponse = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding]; 
    }
    else{
        NSMutableString *temp = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
        [xmlResponse appendString:temp];
        [temp release];
    }

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [self.delegate connectionDidFinish:self];

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{

    [self.delegate connectionDidFail:self]; 

}

我正在调用这个连接器类的 connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate 方法,如下所示:

Connector *con = [[Connector alloc] init];
[con connectToUrl:urlStr withDelegate:self];

我在委托类的 connectionDidFinish 和 connectionDidFail 方法中释放“con”。

请针对 GeneralBlock-3584 泄漏提出解决方案。我已经绞尽脑汁很久了。

【问题讨论】:

    标签: ios iphone memory-leaks nsurlconnection


    【解决方案1】:

    自 iOS4 以来泄漏已经消失。

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      相关资源
      最近更新 更多