lundi 20 juin 2016

Deallocated object is then reallocated?

I'm trying to debug an issue where this loop crashes my app

for( int i = 0; i < 300; i++ ) {
    NSDate *thisDate = [[NSDate date] dateBySubtractingDays:i];
    NSLog(@"here is the date: %@", thisDate);
    NSLog(@"1. here is the class of objects by day keys %@", [objectsByDayKeys class]);
    [objectsByDayKeys addObject:[[DateFormatterManager sharedManager] yyyyMMddStringFromDate:thisDate]];
    NSLog(@"2. here is the class of objects by day keys %@", [objectsByDayKeys class]);
}

I have a repeatable bug that objectByDayKeys has been deinstantiated (enabled zombies) that emerges at some point while this for loop runs. The strange thing is that this doesn't always cause a crash (when it does crash it's an EXC_BAD_ACCESS code = 1 crash). The for loop continues running, sometimes just fine.

Once in a while I get instead of a deallocation error, an error that the array objectsByDayKeys is now a string (get an NSString unrecognizedSelector error from addObject).

We fixed this by not calling the enclosing method so often (it was called a LOT) and this fixed the problem, but I'm wondering what kind of error this is and how I might be able to do better troubleshooting. I tried Build-and-Analyze, running with exceptions, and enabling zombies, but I'm particularly puzzled about how an object can be uninstantiated but then back to instantiated?

Aucun commentaire:

Enregistrer un commentaire