CoreData MagicalRecord save methods crashes on iPhone5 - ios

Currently I'm working with MagicalRecord v2.3.0-beta.3 commit:d18e74fe435359238b9593c03e41c1ee0baa0b78 framework. I'm getting 1 a crash log (from Crashlytics) on iPhone 5 all the time. App is still in development. The crash log looks like below:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x38eee626 objc_msgSend + 5
1 Foundation 0x2f06d02d -[NSError dealloc] + 60
2 libobjc.A.dylib 0x38ef3b6b objc_object::sidetable_release(bool) + 174
3 libobjc.A.dylib 0x38ef40d3 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
4 CoreFoundation 0x2e67d481 _CFAutoreleasePoolPop + 16
5 Foundation 0x2f0778e3 -[NSAutoreleasePool drain] + 122
6 CoreData 0x2e4bdfbf -[NSManagedObjectContext save:] + 942
7 MyApp 0x00162f9f __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke15 (NSManagedObjectContext+MagicalSaves.m:82) // here app crashes
8 CoreData 0x2e5219cd developerSubmittedBlockToNSManagedObjectContextPerform + 88
9 CoreData 0x2e521b13 -[NSManagedObjectContext performBlockAndWait:] + 114
10 MyApp 0x00162e51 -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:] (NSManagedObjectContext+MagicalSaves.m:116)
11 MyApp 0x000a2b0d -[SPNCoreDataHandler parseAndSaveDictionaryReturnOperationArray:withSaving:] (SPNCoreDataHandler.m:70)
12 MyApp 0x00078f21 __102-[SPNApiHandler getAllDataWithDownloadingSuccessBlock:savingSuccessBlock:downloadStatus:failureBlock:]_block_invoke (SPNApiHandler.m:69)
13 MyApp 0x000795b9 __66-[SPNApiHandler sendGetRequestWithPath:successBlock:failureBlock:]_block_invoke (SPNApiHandler.m:174)
14 libdispatch.dylib 0x393cdd53 _dispatch_call_block_and_release + 10
15 libdispatch.dylib 0x393cdd3f _dispatch_client_callout + 22
16 libdispatch.dylib 0x393d06c3 _dispatch_main_queue_callback_4CF + 278
17 CoreFoundation 0x2e714641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
18 CoreFoundation 0x2e712f0d __CFRunLoopRun + 1308
19 CoreFoundation 0x2e67d729 CFRunLoopRunSpecific + 524
20 CoreFoundation 0x2e67d50b CFRunLoopRunInMode + 106
21 GraphicsServices 0x335ec6d3 GSEventRunModal + 138
22 UIKit 0x30fde871 UIApplicationMain + 1136
23 MyApp 0x0009c347 main (main.m:16)
And here's code which I wrote:
NOTE: I removed some parts of this method for sake of readability (that's why method returns void instead of NSArray).
- (NSArray *)parseAndSaveDictionaryReturnOperationArray:(NSDictionary *)dictionary withSaving:(BOOL)saveSynchrounously {
[self truncateAll]; //method which removes all entries in coreData
/* methods below creates entities from array given in dictionary
using [NSManagedObject MR_createEntity] method
e.g. Contact *contact = [Contact MR_createEntity]; */
[self saveContacts:dictionary[#"contact"]];
[self savePeople:dictionary[#"person"]];
[self saveBuildings:dictionary[#"place"]];
[self saveSessions:dictionary[#"session"]];
[self saveLectures:dictionary[#"program"]];
[self savePartners:dictionary[#"partners"]];
[self saveSponsors:dictionary[#"sponsors"]];
[self saveExhibitorsPlans:dictionary[#"exhibitorplan"]];
[self saveMeetingPlans:dictionary[#"meetingplan"]];
[self saveOrganizationalInformation:dictionary[#"info"]];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
//continue executing method...
}
I tried also to use [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:] method but it crashes too.
In other Stackoverflow question someone suggested, that crash can be caused by deleting, creating and saving to many entities at once. In my case it's around 200 deleted entities + 200 new ones. Can it cause crash?
On other devices (iPhone 4s, iPhone 5s, iPad 2, iPad4, iPad mini) it works fine. Any ideas what I'm doing wrong?

Finally I found out what was going on. Tester didn't delete and install an app as I told. Crash appears because DB schema changed. Maybe I should start to think about DB versioning during development to avoid those kind of issues.
Thanks anyone for answers.

Related

iOS10 Open Beta - iOS Core Data Crash on save

I am assuming it is ok to post beta iOS10 issues here, since it is an open beta. The apple forums don't come close to the help one gets on Stackoverflow.
Since the update to iOS10, our users are getting a constant crash when saving the managedObjectContext in CoreData.
This is something that has worked flawlessly since iOS 5.
It only happens on the 64 bit version of iOS10. The 32 bit version works fine.
Here is my simple save code snip:
[self.managedObjectContext performBlockAndWait:^{
NSError *error;
if (![self.managedObjectContext save:&error])
{
NSLog(#"\n\nerror in save 1 %#\n\n", error);
}
}];
[self.managedObjectContext performBlock:^{
NSError *error;
if (![_privateWriterContext save:&error])
{
NSLog(#"\n\nerror in save 2 %#\n\n", error);
}
}];
(Above NSLog reports nothing, as it works in simulator).
This only fails on a 64bit device. I cannot replicate on the simulator. I also cannot replicate in debug on a device due to issues with my only 64 bit device not connecting to Xcode correctly. So I am a bit stuck.
Below is a sample stack trace reported from a user:
Incident Identifier: 7A8DD23B-48A2-4ABF-88E7-67F1E6CDA8D5
CrashReporter Key: 5454e7c7b99a94cd75b6adfa8334bbdf10b859eb
Hardware Model: iPhone8,1
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Date/Time: 2016-07-20 22:23:00.1429 -0400
Launch Time: 2016-07-20 22:21:30.6058 -0400
OS Version: iPhone OS 10.0 (14A5309d)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000985e4beb8
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001850e6eb0 objc_msgSend + 16
1 CoreFoundation 0x0000000185a76740 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:650)
2 CoreFoundation 0x0000000185a75e44 _CFXRegistrationPost + 400 (CFNotificationCenter.c:164)
3 CoreFoundation 0x0000000185a75bc0 ___CFXNotificationPost_block_invoke + 60 (CFNotificationCenter.c:1031)
4 CoreFoundation 0x0000000185ae40cc -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504 (CFXNotificationRegistrar.m:163)
5 CoreFoundation 0x00000001859b9484 _CFXNotificationPost + 376 (CFNotificationCenter.c:1028)
6 Foundation 0x000000018644e9dc -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 (NSNotification.m:482)
7 CoreData 0x0000000187e1dbf4 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidSaveNotificationWithUserInfo:] + 880 (NSManagedObjectContext.m:7381)
8 CoreData 0x0000000187dabb4c -[NSManagedObjectContext(_NSInternalAdditions) _didSaveChanges] + 2156 (NSManagedObjectContext.m:5827)
9 CoreData 0x0000000187d98570 -[NSManagedObjectContext save:] + 3440 (NSManagedObjectContext.m:1532)
10 App 0x000000010008db34 __29-[RPSAppDelegate saveContext]_block_invoke227 + 52 (RPSAppDelegate.m:338)
11 CoreData 0x0000000187e17c68 developerSubmittedBlockToNSManagedObjectContextPerform + 168 (NSManagedObjectContext.m:3529)
12 libdispatch.dylib 0x0000000185525784 _dispatch_client_callout + 16 (object.m:455)
13 libdispatch.dylib 0x000000018552a330 _dispatch_main_queue_callback_4CF + 1000 (inline_internal.h:2421)
14 CoreFoundation 0x0000000185a8a0cc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1793)
15 CoreFoundation 0x0000000185a87cb8 __CFRunLoopRun + 1660 (CFRunLoop.c:3004)
16 CoreFoundation 0x00000001859b78d8 CFRunLoopRunSpecific + 444 (CFRunLoop.c:3113)
17 GraphicsServices 0x00000001873be198 GSEventRunModal + 180 (GSEvent.c:2245)
18 UIKit 0x000000018b9617c8 -[UIApplication _run] + 664 (UIApplication.m:2651)
19 UIKit 0x000000018b95c534 UIApplicationMain + 208 (UIApplication.m:4088)
20 App 0x000000010008c138 main + 152 (main.m:27)
21 libdyld.dylib 0x00000001855585b8 start + 4
Thank you for any ideas.
You are saving _privateWriterContext in a block call of managedObjectContext. This is not allowed. The fact that it worked before is a "false positive".
Instead, you should always only use at the same context that creates the block.

Magical Record Crashed: NSManagedObjectContext Queue EXC_BAD_ACCESS KERN_INVALID_ADDRESS

I'm using Magical Record for Core Data operations.
It seems that the crash I posted below would only happen in iOS 7.
And EXC_BAD_ACCESS KERN_INVALID_ADDRESS means some object is deallocated.
I am not quite sure where the bug is.
Any idea on this? Thanks.
Thread : Crashed: NSManagedObjectContext Queue
0 libobjc.A.dylib 0x39d7c636 objc_msgSend + 21
1 Foundation 0x2fee4d9d -[NSError dealloc] + 60
2 libobjc.A.dylib 0x39d81b6b objc_object::sidetable_release(bool) + 174
3 libobjc.A.dylib 0x39d820d7 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
4 CoreFoundation 0x2f4f5c19 _CFAutoreleasePoolPop + 16
5 Foundation 0x2feef637 -[NSAutoreleasePool drain] + 122
6 CoreData 0x2f336fb9 -[NSManagedObjectContext save:] + 944
7 Branch 0x20f87d __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke20 (NSManagedObjectContext+MagicalSaves.m:82)
8 CoreData 0x2f39a935 developerSubmittedBlockToNSManagedObjectContextPerform + 88
9 CoreData 0x2f39aa7b -[NSManagedObjectContext performBlockAndWait:] + 114
10 Branch 0x20f621 -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:] (NSManagedObjectContext+MagicalSaves.m:128)
11 CoreData 0x2f39a935 developerSubmittedBlockToNSManagedObjectContextPerform + 88
12 libdispatch.dylib 0x3a26cdd7 _dispatch_barrier_sync_f_invoke + 26
13 CoreData 0x2f39aa73 -[NSManagedObjectContext performBlockAndWait:] + 106
14 Branch 0x205831 +[MagicalRecord(Actions) saveWithBlockAndWait:] (MagicalRecord+Actions.m:44)
15 Branch 0x1acdbb __62-[BREmployeeDataController getPositionsAtLocation:completion:]_block_invoke (BREmployeeDataController.m:42)
16 Branch 0x1ad87d __66-[BREmployeeDataController synchronizeStaffAtLocation:completion:]_block_invoke (BREmployeeDataController.m:193)
17 Branch 0x1d215b __116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke80 (AFHTTPSessionManager.m:287)
18 Branch 0x1e326b __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2150 (AFURLSessionManager.m:308)
19 libdispatch.dylib 0x3a25a833 _dispatch_call_block_and_release + 10
20 libdispatch.dylib 0x3a25a81f _dispatch_client_callout + 22
21 libdispatch.dylib 0x3a25a777 _dispatch_main_queue_callback_4CF$VARIANT$up + 254
22 CoreFoundation 0x2f58c8a1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
23 CoreFoundation 0x2f58b175 __CFRunLoopRun + 1300
24 CoreFoundation 0x2f4f5ebf CFRunLoopRunSpecific + 522
25 CoreFoundation 0x2f4f5ca3 CFRunLoopRunInMode + 106
26 GraphicsServices 0x343fb663 GSEventRunModal + 138
27 UIKit 0x31e4214d UIApplicationMain + 1136
28 Branch 0x1a6437 main (main.m:14)
29 libdyld.dylib 0x3a27fab7 start + 2
Are you using ARC? Does MagicalRecord use ARC?
Either you or MagicalRecord is over-releasing some object that an NSAutoreleasePool believes it owns. Then the pool gets popped (when your NSManagedObjectContext finishes the save: operation) and one of the objects in there is garbage. Try running with NSZombies enabled, or use the Allocations Instrument to determine which object is being over-released.

ALAssetsLibrary error - "Too many contexts. No space in contextList."

I've received a couple of crash reports from users. I don't even know where to begin on this one. I am showing images from the asset library in a table view starting with a list of groups. I load the groups with the following code (on the main thread):
- (ALAssetsLibrary *)library {
if (!_library) {
_library = [[ALAssetsLibrary alloc] init];
}
return _library;
}
- (void)determineGroups {
ALAssetsLibrary *lib = [self library];
[lib enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos | ALAssetsGroupPhotoStream | ALAssetsGroupFaces | ALAssetsGroupLibrary | ALAssetsGroupAlbum | ALAssetsGroupEvent usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
if (!_groups) {
_groups = [[NSMutableArray alloc] init];
}
if ([group numberOfAssets]) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
if ([[group valueForProperty:ALAssetsGroupPropertyType] isEqual:#(ALAssetsGroupSavedPhotos)]) {
[_groups insertObject:group atIndex:0];
} else {
[_groups addObject:group];
}
}
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
} failureBlock:^(NSError *error) {
// denied
dispatch_async(dispatch_get_main_queue(), ^{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView reloadData];
});
}];
}
When populating the table view I want to show the number of photos in each group. I do this by calling the "numberOfAssets" method on the group.
This all works just fine most of the time but crashes on rare occasions. Here is one of the stack traces with the relevant info (thread 5 crashed while the main thread was busy getting the number of assets in the group):
Crashed Thread: 5
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Too many contexts. No space in contextList.'
Thread 0:
0 CoreFoundation 0x313a1c42 _CFStringGetLength2 + 26
1 CoreFoundation 0x313aba41 -[__NSDictionaryM objectForKey:] + 133
2 CoreData 0x312b5d2f -[NSSQLOrderIntermediate generateSQLStringInContext:] + 1283
3 CoreData 0x312018f7 -[NSSQLFetchIntermediate generateSQLStringInContext:] + 515
4 CoreData 0x311fe625 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 425
5 CoreData 0x311fe3ad -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 509
6 CoreData 0x311fdfc5 -[NSSQLCore newRowsForFetchPlan:] + 117
7 CoreData 0x311fd73f -[NSSQLCore objectsForFetchRequest:inContext:] + 683
8 CoreData 0x311fd205 -[NSSQLCore executeRequest:withContext:error:] + 469
9 CoreData 0x311fc61d -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1645
10 CoreData 0x311faf17 -[NSManagedObjectContext executeFetchRequest:error:] + 647
11 PhotoLibraryServices 0x366cd4e5 -[PLManagedObjectContext executeFetchRequest:error:] + 49
12 CoreData 0x3121ad07 _faultBatchAtIndex + 623
13 CoreData 0x3121aa53 -[_PFBatchFaultingArray getObjects:range:] + 143
14 CoreData 0x3121a9c1 -[_PFBatchFaultingArray getObjects:] + 41
15 Foundation 0x31cfbbe1 _filterObjectsUsingPredicate + 325
16 Foundation 0x31d01b8d -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] + 273
17 PhotoLibraryServices 0x366d86ad +[PLFilteredAlbum filteredIndexesInAlbum:predicate:] + 265
18 PhotoLibraryServices 0x366d8bd1 -[PLFilteredAlbum filteredIndexes] + 117
19 PhotoLibraryServices 0x366d8d75 -[PLFilteredAlbum countOfFilteredAssets] + 21
20 AssetsLibrary 0x30ce25d5 __31-[ALAssetsGroup numberOfAssets]_block_invoke_0 + 41
21 CoreData 0x31257fd1 developerSubmittedBlockToNSManagedObjectContextPerform + 89
22 libdispatch.dylib 0x3971d4b7 _dispatch_client_callout + 23
23 libdispatch.dylib 0x397219f7 _dispatch_barrier_sync_f_invoke + 31
24 CoreData 0x31258153 -[NSManagedObjectContext performBlockAndWait:] + 175
25 AssetsLibrary 0x30ce414f -[ALAssetsLibrary _performBlockAndWait:] + 135
26 AssetsLibrary 0x30ce8f59 -[ALAssetsGroupPrivate _performBlockAndWait:] + 177
27 AssetsLibrary 0x30ce254b -[ALAssetsGroup numberOfAssets] + 259
Thread 5 Crashed:
0 libsystem_kernel.dylib 0x39804350 __pthread_kill + 8
1 libsystem_c.dylib 0x397b7973 abort + 95
2 MyApp 0x0074685f ___lldb_unnamed_function30167$$MyApp + 27
3 CoreFoundation 0x3145b57f __handleUncaughtException + 615
4 libobjc.A.dylib 0x39306a65 _objc_terminate() + 129
5 libc++abi.dylib 0x38d5307b safe_handler_caller(void (*)()) + 79
6 libc++abi.dylib 0x38d53114 std::terminate() + 20
7 libc++abi.dylib 0x38d54513 __cxa_throw + 123
8 libobjc.A.dylib 0x393069bf objc_exception_throw + 95
9 CoreFoundation 0x3145b15d +[NSException raise:format:] + 1
10 Foundation 0x31d30b13 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 87
11 PhotoLibraryServices 0x366d0afb __addContextToList_block_invoke_0 + 179
12 libdispatch.dylib 0x3971e11f _dispatch_call_block_and_release + 11
13 libdispatch.dylib 0x39721ecf _dispatch_queue_drain$VARIANT$mp + 143
14 libdispatch.dylib 0x39721dc1 _dispatch_queue_invoke$VARIANT$mp + 41
15 libdispatch.dylib 0x3972291d _dispatch_root_queue_drain + 185
16 libdispatch.dylib 0x39722ac1 _dispatch_worker_thread2 + 85
17 libsystem_c.dylib 0x39752a11 _pthread_wqthread + 361
The crash was from an iPad running iOS 6.1.3. The app was built with a Base SDK of iOS 7 GM. The app uses ARC.
Is there something i should be doing different in my code to get the groups?
Definitely it is iOS issue and is reproduced when enumerateGroupsWithTypes:... method contains ALAssetsGroupLibrary inside types enumeration.
You must use either ALAssetsGroupALL (that does not include ALAssetsGroupLibrary)
or you may enumerate types with OR but don't include ALAssetsGroupLibrary to enumeration.
I don't know what to do if you really need ALAssetGroupLibrary in types enumeration.
My code is very similar to yours; if you want to reproduce this issue try to call determineGroups method many times (my issue reproduces when I do this 11 times exactly) but library object must be recreated each time you call this method (f.e. You may remove library at the end of determineGroups method.
Or you may call determineGroups method each time for new receiver.). Also to reproduce this issue don't call determineGroups method inside single run loop
it would be better if you create button and tap on this button would create new receiver and calls determineGroups for it. Now try to tap on this button many times.
Hope my answer will help you.
I fix this by creating a sigleton object when using the ALAssetsLibrary.
+ (instancetype)defaultAssetsLibrary
{
#synchronized(self) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
defaultAssetsLibrary = [[self alloc] init];
});
}
return defaultAssetsLibrary;
}

NSObjectInaccessbileExceptions while merging child context

I understand about NSObjectInaccessbileExceptions in general, and the need to avoid attempting to fault in an object that has been deleted in another managed context/thread.
However, in my user crash reports, I'm seeing an NSObjectInaccessibleException while merging/saving a child NSManagedObjectContext from a background thread (B) into my main context (A), which seems like an unusual scenario.
The only situation I can imagine that could cause such a thing is the following:
change property of object in thread/context (B)
delete object in thread/context A
save context A
save context B
merge A into B and save A -> exception raised because object doesn't exist in A.
Has anybody else seen an exception in while saving the context like this? I tried to reproduce this manually, but failed. Is there some other scenario where this could happen, and are there any tips for dealing with such?
Thanks!
Fatal Exception
NSObjectInaccessibleException
CoreData could not fulfill a fault for '0x1f019da0 <x-coredata://741E65A8-C211-470E-8194-3005F0DFA71C/TrackInfo/p265>'
0 CoreFoundation __exceptionPreprocess + 162
1 libobjc.A.dylib objc_exception_throw + 30
2 CoreData _PFFaultHandlerLookupRow + 1482
3 CoreData -[NSFaultHandler fulfillFault:withContext:] + 24
4 CoreData -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 236
5 CoreData -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 96
6 CoreData -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 918
7 CoreData __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 + 564
8 libdispatch.dylib _dispatch_barrier_sync_f_slow_invoke + 96
9 libdispatch.dylib _dispatch_client_callout + 22
10 libdispatch.dylib _dispatch_main_queue_callback_4CF + 228
11 CoreFoundation __CFRunLoopRun + 1288
12 CoreFoundation CFRunLoopRunSpecific + 356
13 CoreFoundation CFRunLoopRunInMode + 104
14 GraphicsServices GSEventRunModal + 74
15 UIKit UIApplicationMain + 1120
16 app main.m line 13 main
17 app start
You may try using the following line while you are creating your child context:
privateManagedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy

Low memory warning causes a crash on iOS5 - unloadViewForced

I have been able to replicate a low-memory crash on iOS devices that are running iOS5. Every time the stack trace points to the same place, so I know exactly where the problem is. Unfortunately I don't know how to fix it. As you can see below, the crash occurs when CatViewController receives a memory warning. At that point its view gets forcibly unloaded, then the crash happens:
0 libobjc.A.dylib 0x37174f7e objc_msgSend + 22
1 UIKit 0x317eab66 -[UIViewController unloadViewForced:] + 130
2 UIKit 0x31932492 -[UIViewController purgeMemoryForReason:] + 58
3 MyApp 0x001353c0 -[CatViewController didReceiveMemoryWarning] (CatViewController.m:89)
4 Foundation 0x339e34f8 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 12
5 CoreFoundation 0x35178540 ___CFXNotificationPost_block_invoke_0 + 64
6 CoreFoundation 0x35104090 _CFXNotificationPost + 1400
7 Foundation 0x339573e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
8 Foundation 0x33958c14 -[NSNotificationCenter postNotificationName:object:] + 24
9 UIKit 0x318fd26a -[UIApplication _performMemoryWarning] + 74
10 UIKit 0x318fd364 -[UIApplication _receivedMemoryNotification] + 168
11 libdispatch.dylib 0x37ae6252 _dispatch_source_invoke + 510
12 libdispatch.dylib 0x37ae3b1e _dispatch_queue_invoke$VARIANT$up + 42
13 libdispatch.dylib 0x37ae3e64 _dispatch_main_queue_callback_4CF$VARIANT$up + 152
14 CoreFoundation 0x3517f2a6 __CFRunLoopRun + 1262
15 CoreFoundation 0x3510249e CFRunLoopRunSpecific + 294
16 CoreFoundation 0x35102366 CFRunLoopRunInMode + 98
17 GraphicsServices 0x3476d432 GSEventRunModal + 130
18 UIKit 0x31779e76 UIApplicationMain + 1074
19 MyApp 0x00087142 main (main.m:16)
20 MyApp 0x000870c8 start + 32
So I believe this has something to do with the way the view is getting unloaded on iOS5. This view controller is not removing itself from any notifications, so this solution doesn't work. Line 89 of CatViewController is just this:
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; //this is line 89
}
And viewDidUnload just looks like this:
- (void)viewDidUnload {
[self setBackgroundView:nil];
[self setContentView:nil];
[self setSomeScrollView:nil];
[super viewDidUnload];
}
Any ideas on how I can handle this gracefully without crashing?
EDIT: Here's more info on another crash report:
0 CoreFoundation 0x351ac88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3717a259 objc_exception_throw + 33
2 CoreFoundation 0x351afa9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x351ae915 ___forwarding___ + 301
4 CoreFoundation 0x35109650 _CF_forwarding_prep_0 + 48
5 UIKit 0x317eabdf -[UIViewController unloadViewForced:] + 251
6 UIKit 0x31932499 -[UIViewController purgeMemoryForReason:] + 65
7 MyApp 0x000d541b -[CatViewController didReceiveMemoryWarning] (CatViewController.m:96)
Your app is not crashing because it is out of memory. In your crash report, you can see that the exception thrown was actually [NSObject doesNotRecognizeSelector:].
Firstly, you should move those set to nil statements to didReceiveMemoryWarning; this is the preferred method since viewDidUnload is no longer supported in iOS 6.
Secondly, to find your crash, step through those statements where you set your properties to nil and make sure none of those cause the crash. Note that you will only have methods with those signatures (self set<propertyName>:]) if those variables are declared as properties, not as mere instance variables.

Resources