1

I'm getting an EXEC_BAD_ACCESS error when I release a CXMLDocument.

Here's my very simple code which has no dependencies:

@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];
}

If I comment out CXMLElement *rootElement = [xmlDoc rootElement]; or if I retain it, there is no error.

How can calling [xmlDoc rootElement] cause xmlDoc to get over released? Is this a TouchXML bug or am I missing something really basic?

Similar question here, but no valid answers: Weird crash if I try to release CXMLDocument

Community
  • 1
  • 1
Brandon O'Rourke
  • 24,165
  • 16
  • 57
  • 58

3 Answers3

0

I used TouchXML quite often, and (fortunately?) I did not have this problem up to now, but it just happened ...

I posted a solution here: Memory crash using [CXMLNode nodesForXPath] with namespace mappings

Community
  • 1
  • 1
TheEye
  • 9,280
  • 2
  • 42
  • 58
0

Is that the correct way of getting rootElement? I've never used TouchXML but from what I can find, it seems that getting the rootElement is done accordingly

NSArray *foundRoots = [theXMLDocument nodesForXPath:@"//Root"  error:&xmlError]; 
CXMLElement Root = [foundRoots objectAtIndex:0];
Man of One Way
  • 3,904
  • 1
  • 26
  • 41
0

The crash goes away when I turn Guard Malloc turned off. Assuming that Guard Malloc is reliable, this looks like it's a Touch XML bug.

Brandon O'Rourke
  • 24,165
  • 16
  • 57
  • 58