I'm running into a repeatable crash when calling -performFetch on my NSFetchedResultsController in what SEEMS like a data-related crash:
NSFetchedResultsController *aFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:sectionnamekeypath
cacheName:cacheName];
aFetchedResultsController.delegate = self;
NSError *error = nil;
if (NO == [aFetchedResultsController performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
It crashes at the performFetch() call. I turned on Zombie checking and it printed:
*** -[CFString isNSString__]: message sent to deallocated instance 0x12c6071d0
I've checked all of the strings in my function and I can't find a string that has that address. I NSLog()'d all of the strings along with their address locations. I figured it would break on whatever NSLog() line that referenced the string in question, but all of them were still valid.
This makes me think this is a problem inside NSFetchedResultsController.performFetch() but it's hard to imagine that they have this kind of bug. So, what else can I do to find out what string this is?
I haven't run into problems like this since we switched over to ARC. I'm not sure how to figure out where this string comes from.
It SEEMS like this is data related though. My app pulls down data from our server, imports it into Core Data, and then uses the NSFetchedResultsController to show the data in a UITableView. I can login as various different users, download their data, and the FRC fetches and works just fine. But when I login as this one particular user, then it crashes. That user is one of our biggest users and their dataset is thousands and thousands of records, so it's not something I can easily look through to visually find things that might be weird. Doing further testing and will update this if I find any new info.
I have -no- idea how this could have been the problem and potentially someone who understands the relationship between NSString and CFString could explain it to me.
My FRC (NSFetchedResultsController) took a sectionNameKeyPath
to the initializer so that it would automatically break up the results into appropriate sections for my table view.
The sectionNameKeyPath
was namefirstletter
which is a method that I have defined in the base class of all of my Core Data objects.
In my -namefirstletter
method, I had this code at the end:
NSString *uppercasefirstletter = [firstletter uppercaseString];
return uppercasefirstletter;
This code has been working for 6+ years, never had a problem. But it's suddenly a problem, so I'm wondering if there was a change in the latest iOS or something. Now, when I execute my FRC with the above code in my sectionNameKeyPath function, it crashes every time.
However, this fixed it:
NSString *uppercasefirstletter = [NSString stringWithString:[firstletter uppercaseString]];
return uppercasefirstletter;
Now it works every time.
Is -uppercaseString
returning me an improperly managed reference? Can anyone explain this to me?