Search code examples
ioscrashkissxml

My app crashed when I created autorelease object of DDXMLDocument


My app did't crashed.

DDXMLDocument *d = [[DDXMLDocument alloc] initWithData:abookConnData options:0 error:nil];
books = [d nodesForXPath:@"abooks/abook" error:nil];

I changed object of DDXMLDocument to autorelease and my app began crashed. But Why?

DDXMLDocument *d = [[[DDXMLDocument alloc] initWithData:abookConnData options:0 error:nil] autorelease];
books = [d nodesForXPath:@"abooks/abook" error:nil];

My app crashed in the DDXMLNode. [DDXMLNode XMLStringWithOptions:]

enter image description here


Solution

  • You don't give enough code to say for sure, but this is almost certainly a case where your DDXMLDOcument* (d) is being released before you use it.

    Try turning on Zombie detection and also put a breakpoint on Exception. Often, that can lead you to the exact line of code where the problem is.

    Another trick for debugging is to create a subclass of DDXMLDocument and override ALLOC and RELEASE to call NSLog() the event (then [super alloc] or [super release]!) so you can watch what's happening.