This post is from the WWDC26 Widgets & Live Activities Q&A.
If the user has a lot of widgets the timeline generator can wind up getting killed. Is there any recommendations on how to deal with this? Is there for example any equivalent of applicationDidReceiveMemoryWarning() ?
If generating your timeline is taking a long time or you are hitting memory limits there are a few things you might consider:
- How many timeline entries are you generating? Would it be possible to generate fewer entries more quickly?
- Wrapping operations in autorelease pools, and ejecting objects from RAM as quickly as possible.
- Pre-process images so they are not enormous. You will likely need to do some resizing in the extension to support all widget sizes, but starting with a smaller image would help.
- Can your widget extension be more focused? Only fetch the information that is absolutely necessary for your widget.
- What timeline reload policy are you using? If you generate fewer entries, depending on your use case, the
.atEndpolicy would allow the system to reload your widgets when the timeline entries have been exhausted. Alternatively, if you know there is a specific date/time you will need a reload you could use the.afterDatereload policy to have more control on when a reload will be issued. Developer documentation. - Alternatively, you could pre-compute the data needed in your app and store this in a shared database. Your widget extension could just read the data needed from the database when it gets reloaded. When data changes you could send a push to your app, update the data, and reload your widget manually with the WidgetCenter APIs.
Thanks for the question!