2010-07-06 66 views
0

這裏我泄漏NSURL連接在我的libxml解析器任何人都可以告訴如何解決它。獲取內存泄漏在NSURL連接Iphone sdk

哪裏泄漏產生的代碼是:

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

任何人的幫助下將渣土讚賞。

謝謝, Monish。

回答

0

嗯嘗試發佈theRequest好像它會被複制到NSURLConnection init中,這會增加保留計數。另一個嘗試將自己處理con的內存管理

+0

'theRequest'應該不需要釋放,因爲它是通過便捷方法創建的,而不是保留的。 – thelaws 2010-12-24 20:10:05