【问题标题】:TouchXML over release problemTouchXML 过度发布问题
【发布时间】:2011-07-29 21:40:40
【问题描述】:

我在发布 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 错误还是我错过了一些非常基本的东西?

此处有类似问题,但没有有效答案:Weird crash if I try to release CXMLDocument

【问题讨论】:

    标签: iphone objective-c touchxml


    【解决方案1】:

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

    NSArray *foundRoots = [theXMLDocument nodesForXPath:@"//Root"  error:&xmlError]; 
    CXMLElement Root = [foundRoots objectAtIndex:0];
    

    【讨论】:

    • 我认为这相当于我的代码。我得到同样的 EXEC_BAD_ACCESS 错误。
    • 你确定你的xml中有根吗?里面没有错别字吗?
    • 是的,它在这个 XML 中找到了一个根 @"//test":@"Test!"
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      我经常使用 TouchXML,而且(幸运的是?)我到现在都没有这个问题,但它只是发生了......

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-16
        • 2022-01-18
        • 2010-10-11
        • 1970-01-01
        • 2016-10-08
        • 1970-01-01
        • 2011-03-25
        相关资源
        最近更新 更多