我使用下面的函数来把我的XML的每个“设施”节点在NSMutable阵列:自动释放池和内存管理
-(void) grabXML {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];
NSArray *nodes = [[doc rootElement] nodesForXPath:@"//facilities" error:nil];
for (CXMLNode *itemNode in nodes)
{
for (CXMLNode *eventNode in [itemNode children])
{
if ([[eventNode name] isEqualToString:@"facility"]) {
[content addObject:[eventNode copy]];
}
}
}
loading = FALSE;
[table reloadData];
[pool release];
}
注意,游泳池是必要的,因为我叫grabXML方法在一个单独的线程中。
使用仪器我可以看到下面的行产生泄漏
[content addObject:[eventNode copy]];
如果我将其更改为
[content addObject:eventNode];
我不能稍后访问XCMLNode(它似乎为空)。
我能避免泄露把这个在我的dealloc方法:
for (CXMLNode *node in content) {
[node release];
}
但我觉得我做错了什么......或者至少我不知道发生了什么事情的...请你能给我一点线索吗?
谢谢!