5
votes

Core Data model attribute with type binary and "Allow External Storage" enabled cause crash in NSPersistentCloudKitContainer sync mechanism.

This happens only on receiving device, meaning upload to CloudKit is successful, but download from CloudKit causes crash when in NSManagedContext.

<NSSQLSaveChangesRequestContext: 0x281ec8420> , *** NSAllocateMemoryPages(28317598) failed with userInfo of (null)

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** NSAllocateMemoryPages(30318498) failed

This is obviously a memory crash, but I can't figure out how to workaround it, it seems to be an iOS bug.

1
My guess is that it is not a bug and you're just overloading the system. Read this, it may help... blog.five.agency/…andrewbuilder
...and the Apple Docs indicate that the process to allocate a new block of memory has failed.andrewbuilder
@andrewbuilder I understand that the crash is caused during memory allocation, more than that I know that it tries to allocate memory specifically for the binary attribute(exact size byte to byte). What I don't understand is why it's doing it? My expectations of how it should work: 1) I create a binary attribute and allow external storage, i.e. for large values core data stores a file + reference to file 2) CloudKit Stores is as CKAsset 3) At no point during synchronization, this data should be lifted into the memory...Alexandr Mazanov

1 Answers

3
votes

You are not alone! It's not something you are doing wrong, if you disable "Allow External Storage" option (and delete the app from your device to avoid migration crash) it will sync fine. Obviously it's something wrong with "Allow External Storage" option, and files bigger than a few mb.

In my app I was syncing png images. Those who were bigger than ~28mb (if I can recall the size correctly), couldn't sync to a device and made it crash.

I submitted a bug report with Feedback Assistant, and for the first time Apple asked for more details. I send them a sample app.

Edit: Good news folks! Apple flagged my bug report with "Potential fix identified - For a future OS update". I'll check Xcode 12 beta if its fixed and report back.

Edit 2: For iOS 14 and Xcode 12, the bug has been fixed! Yay! 🎉