我正在使用 TouchXML 来解析 XML。虽然我在“配置文件”模式下运行相同。我可以看到内存泄漏。我该如何解决这个问题?
-(NSMutableArray *) grabXML:(NSData *)xmlData andQuery:(NSString *)query {
NSMutableArray *blogEntries = [[[NSMutableArray alloc] init] autorelease];
CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithData:xmlData options:0 error:nil] autorelease];
NSArray *resultNodes = [rssParser nodesForXPath:query error:nil];
for (CXMLElement *resultElement in resultNodes) {
NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];
int counter;
for(counter = 0; counter < [resultElement childCount]; counter++) {
[blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
}
for( int i = 0; i < [[resultElement attributes] count]; i++) {
CXMLNode *node = [[resultElement attributes] objectAtIndex:i];
[blogItem setObject:[[resultElement attributeForName:[node name]] stringValue] forKey:[node name]];
}
[blogEntries addObject:[blogItem copy]];
[blogItem release];
}
return [blogEntries copy];
}
我以下面提到的格式调用上述方法。
NSMutableArray *arr = [[self grabXML:responseData andQuery:@"//wsCheneliereResult"] autorelease];