Memory Management for XML Parsing
Memory Management for XML Parsing
- Subject: Memory Management for XML Parsing
- From: Bing Li <email@hidden>
- Date: Sun, 12 Jun 2011 17:44:03 +0800
Dear all,
I got another memory management problem. When an XML is received, it must be
parsed using the below method. When a large number of XML is received, the
receiver's memory is increased slowly. I tried to figure out where the
memory leaks. I guess the method might cause this problem.
The NSArray, nodes, is created by xmlDoc. Since the method is not the owner,
nodes should be released here. One value of the array must be returned. Does
the value leak? The method below is correct?
Thanks so much for your help!
Best regards,
Bing
+ (NSString *)read:(NSString *)xml Path:(NSString *)xPath
{
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xml
options:NSXMLDocumentTidyXML error:NULL];
NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];
[xmlDoc release];
if ([nodes count] > 0)
{
return [[nodes objectAtIndex:0] stringValue];
}
else
{
return Constants.WWW.EMPTY_STRING;
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden