TouchXML over release problem
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:ani开发者_Python百科mated];
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
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];
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.
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
精彩评论