views:

60

answers:

1

Hi,

I have googled a lot and read a lot about the leaks issue with NSURLConnection, but none of them gives a definite answer as to what is the solution to overcome these leaks. I create an asynchronous connection and every time the connection is established, I get a GeneralBlock-3584 leak. Sometimes the responsible library is shown to be Foundation [NSThread start] frame. Some instances of GeneralBlock-3584 have CFNetwork HostLookup_Master::HostLookup_Master(__CFString const*, InheritEnum<_ExtendedHostInfoType, CFHostInfoType>, __CFHost*, CFStreamError*) as responsible frame. I tried setting NSURLCache size to 0 as suggested by some. Howvever, even that doesn't work.

Here is what my connector class looks like:

-(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]; 

}

And I am calling this connector class's connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate method as below:

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

I am releasing 'con' in connectionDidFinish and connectionDidFail methods of delegate class.

Please suggest a solution for the GeneralBlock-3584 leaks. I have been racking my brains for long.

A: 

The leaks have gone away since iOS4.

Hetal Vora