views:

31

answers:

1

Hi guys,

Here Im getting leak at the NSURL connection in my libxml parser can anyone tell how to resolve it.

The code where leak generates is:

- (BOOL)parseWithLibXML2Parser
{
BOOL success = NO;
ZohoAppDelegate *appDelegate = (ZohoAppDelegate*) [ [UIApplication sharedApplication] delegate];
NSString* curl;
if ([cName length] == 0) 
{
curl = @"https://invoice.zoho.com/api/view/settings/currencies?ticket=";
curl = [curl stringByAppendingString:appDelegate.ticket];
curl = [curl stringByAppendingString:@"&apikey="];
curl = [curl stringByAppendingString:appDelegate.apiKey];
curl = [curl stringByReplacingOccurrencesOfString:@"\n" withString:@""];    
}
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:curl]];

NSLog(@"the request parserWithLibXml2Parser %@",theRequest);
NSURLConnection *con = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];//Memory leak generated here at this line of code.

//self.connection = con;
//[con release];
// This creates a context for "push" parsing in which chunks of data that are 
// not "well balanced" can be passed to the context for streaming parsing. 
// The handler structure defined above will be used for all the parsing. The
// second argument, self, will be passed as user data to each of the SAX
// handlers. The last three arguments are left blank to avoid creating a tree
// in memory.
_xmlParserContext = xmlCreatePushParserCtxt(&simpleSAXHandlerStruct, self, NULL, 0, NULL);
if(con != nil) 
{
    do 
    {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    } while (!_done && !self.error);
}
if(self.error)
{
    //NSLog(@"parsing error");
    [self.delegate parser:self encounteredError:nil];
} else 
{
    success = YES;
}
return success;
}

Anyone's help will be muck appreciated .

Thank you, Monish.

A: 

Hmm try releasing theRequest seems like it will be copied in the NSURLConnection init which increases the retain count. Another try would be handle the memory management of con by yourself

ReaperXmac