I have an app that capture the battery level in a background process and then adds it to an array it keeps in memory until onStop is called.This 'flat' array is a succession of three numbers (time stamp, battery level (*10 to get a decimal without wasting the space of float) and solar level).
Here's what that array looks like with just 4 'elements' in it
[1752038233,221,0,1752038271,220,0,1752038338,219,0,1752038398,217,0]
This array is read from storage in the getInitialView and getGlanceView function, lives in the app memory, gets new elements added to it in the onBackgroundData function and then put back into Storage in the onStop function.
With time, this array grows and on my Fenix7S Pro, when it reaches just 715 of those elements, I get a Out of Memory crash while trying to store the array back into the storage from the glance process. That's just 8544 bytes (about 10K bytes according to the Memory Usage Stat) in the Simulator. The glance process isn't large by itself. The Memory Stats shows a peak of 36KB out of 60KB in the simulator using the data my device had in its storage (although the crash doesn't happen in the Simulator, just my real device)
I need that array as the app will show a graph of battery usage over time. How would you go about to prevent the Glance process from running out of memory or is this a size limit an array can be stored in Storage? I know that a background process can't pass more than around 8K through Background.exit() function but that's not what I'm doing. Through the .exit function, I might have an overnight of data pushed through its onBackgroundData function, which would be around 1KB of data. It's just when I store back that array from the Glance process that I get the Out of Memory crash.
Thanks.