wdchild
wdchild

Reputation: 51

NSXMLParser "elementName" deallocated prematurely in didStartElement: protocol method

I have been using a NSXMLParser subclass for over six months with no problems in Snow Leopard. When I ported to Mavericks, suddenly, I started to get weird crashes in the middle of the import operation. I used Zombies to see what the problem was, and it appears that the elementName parameter in NSXMLParser's protocol method is being deallocated prematurely. Here's the method.

- (void) parser: (SmartParser *) parser
didStartElement:(NSString *)elementName 
   namespaceURI:(NSString *)namespaceURI 
  qualifiedName:(NSString *)qName 
     attributes:(NSDictionary *)attributeDict
{
    if (nil != elementName) {
        NSLog(@"STARTING: elementName is %@\n", elementName); // <= error here
        if ([elementName isEqualToString: @"Root"]) {

[ A series of checks for elementName values follows. And, incidentally, the if (nil != elementName) { check and ensuing NSLog statement were added only to help pinpoint the error, since before that I only knew it crashed at didStartElement: .]

The error message I get is: *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x600000c326c0

Running Zombies, I get: elementName NSString * class name = _NSZombie_CFString 0x0000600000c326c0

So it appears that elementName is turned into a Zombie string. I never modify elementName since it is the parameter supplied by the protocol method. The rest of my protocol methods are pretty standard.

Oddly, the exact same code seems to work fine on the exact same data in El Capitan, but for now I need to work in Mavericks. Also, it happens with some data but not others, even though the data is all straight XML and has been used multiple times in the past with no issues. Does anyone have any idea what is going on? Could this be a weird configuration issue specific to Mavericks. Thanks for the help.

Upvotes: 0

Views: 24

Answers (1)

wdchild
wdchild

Reputation: 51

OK, this is somewhat dissatisfying, but I have "solved" the issue by switching to ARC. The import seems to work fine now so long as I don't run it in a background operation.

It does not really explain how my parser could remain in memory but Apple's elementName variable was getting deallocated.

Upvotes: 0

Related Questions