I'm working on a glance that preloads a JSON file via a web request and caches it in storage for the widget. Since the JSON can be fairly large, I need to implement safeguards to prevent the glance from crashing. If there isn't enough memory available, the glance should simply skip caching the JSON - letting the widget handle the request instead when it's launched.
Handling large JSONs during reception is straightforward: if it's too big, I get a -403 error. But writing to storage seems to be much more memory-intensive. Here, I need to check in advance how much memory is available and try to predict whether storing the JSON will actually succeed.
While experimenting, I noticed something surprising. A modest 3.5kB JSON results in a Dictionary from Communications
that consumes over 12kB of memory. Then, to store that Dictionary, I need an additional 24kB of free memory. So in total, that small 3.5kB JSON ends up requiring around 36kB of memory throughout the process.
Have you seen similar behavior in your experience?