WidgetKit memory limit and CoreData+CloudKit issue

I have my iOS app with a WidgetKit extension. The app is used for storing lists of any data that the user wishes to, and the widget shows a few of the items, such as upcoming birthdays, etc.

The app and widget extension use CoreData+CloudKit, sharing the same database which is about 350mb currently. When the widget tries to load, it would seem that the size of the database is causing my widget to use more than 30mb of memory (about 45mb when run in the simulator). On a physical device (iPhone 13 Pro Max) using more than 30mb makes the widget crash out while updating its content.

This is very frustrating as the iOS app uses about 50mb of memory and it's perfectly fine with it, but I am unable to use the same data to power my widget.

I have considered maybe using some kind of temporary in memory data for my widgets, updated by the app, but the data would change regularly and you'd expect it to change without opening the app. e.g. A widget showing a list of upcoming birthdays should update each day, rather than rely on the user to open the app first.

Is it possible to raise or remove the widget memory limit of 30mb?

Or, is there some way to make CoreData use a lot less memory? It appears to be when I make a call to loadPersistentStores that the memory usage suddenly shoots up. I'm guessing that it's loading some kind of indexing data. I'm not even trying to read any data before it maxes out. My widget only sets up CoreData and then does loadPersistentStores and then boom!

I've tried lots of googling, searching these forums, and ChatGPT, and none have given me any answers that actually work. ChatGPT gives me lots of answers that don't work lol. I'm hoping that somebody has answers that they've actually tried and know do work.

Many thanks for any help, as this is super frustrating!

Wondering if you found a solution? Facing the same problem now with SQLite and memory usage

WidgetKit memory limit and CoreData+CloudKit issue
 
 
Q