WidgetKit Memory Leak on Images

Hello, I'm experimenting with the WidgetKit template and noticed that adding Images seems to generate a memory leak that terminates my app after surpassing the 30Mb limit. Any idea on how to make images work on widgets?
Answered by Systems Engineer in 614250022
Hey!

Yes this is something we are aware of. Certain large images can cause your memory to go over the 30MB limit and cause a Jetsam.

If you could file a feedback, I'd like to know two things:
  1. Specifics about your images—where did you get them from, how are you trying to display them (Image(url:) versus Image(cgImage:)), and how many timeline entries you are returning.

  2. Can you clarify what you mean by "memory leak". What specific things have you seen (memory graph files, Xcode, Instruments traces, etc) that say there are memory leaks? If you just mean that your process is crashing (we call it Jetsamming) because of your images then that is not a leak that's just a memory problem.

For everyone else reading this: We are aware that certain images (mostly CGImages) can cause memory issues which the system does not handle and you crash (again, we call it a Jetsam). We are working on this but if you encounter this please file a feedback. The best thing to do to avoid this is:
  1. Use URL-backed images.

  2. Return less entries.




Accepted Answer
Hey!

Yes this is something we are aware of. Certain large images can cause your memory to go over the 30MB limit and cause a Jetsam.

If you could file a feedback, I'd like to know two things:
  1. Specifics about your images—where did you get them from, how are you trying to display them (Image(url:) versus Image(cgImage:)), and how many timeline entries you are returning.

  2. Can you clarify what you mean by "memory leak". What specific things have you seen (memory graph files, Xcode, Instruments traces, etc) that say there are memory leaks? If you just mean that your process is crashing (we call it Jetsamming) because of your images then that is not a leak that's just a memory problem.

For everyone else reading this: We are aware that certain images (mostly CGImages) can cause memory issues which the system does not handle and you crash (again, we call it a Jetsam). We are working on this but if you encounter this please file a feedback. The best thing to do to avoid this is:
  1. Use URL-backed images.

  2. Return less entries.




Great, thanks for the quick response. I was using a 650Kb image and that's why I thought that a memory leak may be causing the 30MB limit to be reached.

Using a 6Kb image now and it's working.

I have added all this information to the feedback I submitted earlier.

Great work with widgets!
Another thought that solved this exact issue for me: prepare the images in the placeholder, getSnapshot, and getTimeline functions when there are more resources available, setting the actual display process free from such operations.
WidgetKit Memory Leak on Images
 
 
Q