我从 Internet 加载数据,并在另一个线程中使用 DDXML 解析器对其进行解析。这是代码(回调connectionDidFinishLoading:正在后台线程中,我在后台线程中安排了URLConnection):
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"connection did finish load");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
DDXMLDocument *xdoc = [[DDXMLDocument alloc] initWithData: receivedXmlData options:0 error: NULL];
NSLog(@"document retainCount1 = %d", [xdoc retainCount]);
NSArray *nodes = [xdoc selectNodes: @"./items/item"];
NSLog(@"document retainCount2 = %d", [xdoc retainCount]);
for (DDXMLElement *tabXmlItem in nodes)
{
// here is the parsing
}
NSLog(@"document retainCount3 = %d", [xdoc retainCount]);
[xdoc release];
[receivedXmlData setLength:0];
[pool drain];
[pool release];
}
我在内存分配器中看到:DDXMLDocuments、DDXMLNodes、DDXMLElements 在解析结束后仍然存在。因此,内存中有大量的 CFString 和 CFData。为什么这些对象没有被清除?也许,我错误地使用了自动释放池或 DDXML 解析器感到惊讶?