1

我在发布 CXMLDocument 时收到 EXEC_BAD_ACCESS 错误。

这是我非常简单的代码,它没有依赖项:

@implementation TestViewController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    NSError *xmlError = nil;    
    CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithXMLString:@"<test></test>" options:0 error:&xmlError];
    CXMLElement *rootElement = [xmlDoc rootElement]; // Unused local variable   
    [xmlDoc release];
}

如果我注释掉CXMLElement *rootElement = [xmlDoc rootElement];或保留它,则没有错误。

调用如何[xmlDoc rootElement]导致 xmlDoc 过度释放?这是一个 TouchXML 错误还是我错过了一些非常基本的东西?

此处有类似问题,但没有有效答案:如果我尝试释放 CXMLDocument,则会发生奇怪的崩溃

4

3 回答 3

0

这是获取rootElement的正确方法吗?我从未使用过 TouchXML,但据我所知,似乎获取 rootElement 是相应完成的

NSArray *foundRoots = [theXMLDocument nodesForXPath:@"//Root"  error:&xmlError]; 
CXMLElement Root = [foundRoots objectAtIndex:0];
于 2011-07-29T22:11:55.240 回答
0

当我关闭 Guard Malloc 时,崩溃消失了。假设 Guard Malloc 是可靠的,这看起来像是一个 Touch XML 错误。

于 2011-08-23T13:31:43.413 回答
0

我经常使用 TouchXML,而且(幸运的是?)到目前为止我还没有遇到这个问题,但它只是发生了......

我在这里发布了一个解决方案: Memory crash using [CXMLNode nodesForXPath] with namespace mappings

于 2013-09-24T08:08:50.457 回答