Just in case somebody comes here with this or a similar problem - it sounds like the problem described here (https://github.com/TouchCode/TouchXML/issues/11), which I just happened to experience too. In essence it's a EXC_BAD_ACCESS error because the xml document is freed earlier than its child nodes, and when the child nodes want to dealloc themselves they crash.
I did not dig too deep into the TouchXML code, but the following changes to TouchXML seem to fix the problem and also do not lead to any memory leaks (I checked in Profiler):
In CXMLDocument.m:
-(void)dealloc
{
// Fix for #35 http://code.google.com/p/touchcode/issues/detail?id=35 -- clear up the node objects first (inside a pool so I _know_ they're cleared) and then freeing the document
@autoreleasepool {
//### this is added ### fix for BAD_ACCESS on CXMLNode after releasing doc - get rid of all nodes in nodePool first to make sure they are released before the doc is released
NSArray* allObjects = [nodePool allObjects];
for(CXMLNode* child in allObjects)
{
[nodePool removeObject:child];
[child invalidate];
}
//### until here ###
nodePool = NULL;
}
//
xmlFreeDoc((xmlDocPtr)_node);
_node = NULL;
//
}
In CXMLNode.h:
//### add manual dealloc function ###
-(void)invalidate; // added to prevent BAD_ACCESS on doc release ...
And in CXMLNode.m:
//### invalidate function added to be able to manually dealloc this node ###
-(void)invalidate {
if (_node)
{
if (_node->_private == (__bridge void *)self)
_node->_private = NULL;
if (_freeNodeOnRelease)
{
xmlFreeNode(_node);
}
_node = NULL;
}
}