如果我尝试发布CXMLDocument,则会发生奇怪的崩溃 [英] Weird crash if I try to release CXMLDocument

查看:70
本文介绍了如果我尝试发布CXMLDocument,则会发生奇怪的崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TouchXML解析一些XML,并且崩溃-EXC_BAD_ACCESS。我通过反复试验发现,如果不发布我分配的CXMLDocument,那么一切都很好。这是我的代码:

I am parsing some XML using TouchXML and I am getting a crash -EXC_BAD_ACCESS. What I found out through trial and error was that if I don't release my CXMLDocument (which I allocate), then everything is fine. Here's my code:

- (NSArray *)getLookUps {

    //Do some stuff and then...

    NSData *tempData = [NSURLConnection sendSynchronousRequest:request 
                                                 returningResponse:nil 
                                                             error:nil];



        CXMLDocument *xmlDoc = [[CXMLDocument alloc] initWithData:tempData options:0 error:nil];
        NSDictionary *mappings = [NSDictionary dictionaryWithObject:@"http://****/****" 
                                                             forKey:@"****"];

        NSLog(@"%@", [[NSString alloc] initWithData:tempData encoding:NSUTF8StringEncoding]);
        NSArray *orders = [[xmlDoc rootElement] nodesForXPath:@"//****:Unit" 
                                            namespaceMappings:mappings 
                                                        error:nil];

        NSMutableArray *units = [NSMutableArray arrayWithCapacity:200];

        for (CXMLElement *order in orders) {
            NSArray *nodes = [order children];
            NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:[nodes count]];

            for (CXMLElement *node in nodes) {
                [dictionary setObject:[node stringValue] forKey:[node name]];
            }
            [units addObject:dictionary];
        }

        //[xmlDoc release];
    return units;
}

请参见第二行, [xmlDoc版本] 。我已将其注释掉,因为如果不这样做,它将崩溃。我究竟做错了什么?谢谢。

See on the 2nd last line, [xmlDoc release]. I have commented that out, because it crashes if I don't. What am I doing wrong? Thanks.

推荐答案

已报告此错误,并在较新版本的库中将其标记为已修复。

This bug was reported and is flagged as fixed in the newer versions of the library.

http://code.google。 com / p / touchcode / issues / detail?id = 35

我还没有测试过它是否已修正,请在该URL上添加注释暗示不是。

I haven't tested to see if it is actually fixed, a comment at that URL suggests that it isn't.

在我看来,应该完全避免使用此库。对于iOS应用程序,使用libxml2的原因有几个:

In my opinion, this library should be avoided altogether. For iOS apps, use libxml2 for several reasons:


  • 已通过并通过

  • 快速高效

  • 构建基于节点的XML表示可能会更易于编码,但由于您始终将整个文档存储在内存中,因此会浪费内存。解析时,您可能不止一次拥有它。相反,您应该设计代码以使用libxml2方法。一旦开始解析大量文档,您将同意。

这篇关于如果我尝试发布CXMLDocument,则会发生奇怪的崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆