problem with makeWebRequest w/ json response

Sorry if this has been covered, but I don't think it has.

I have a background service that's pulling data from a rest api. The api (was) returning a dictionary as json data. This would work as long as the json data was very small - like 400 bytes. But when I got to around 600 bytes, it fails. (-403 - NETWORK_RESPONSE_OUT_OF_MEMORY)

If I change the request to expect 'text/plain', and change the response to match, it will succeed. Of course, now I have a blob of unparsed json that I have to deal with.

It seems to me that the background process is running out of memory when parsing the json response and turning it into a dictionary object. Has anyone else run into this?

The dictionary has 38 key/value pairs - not an unreasonable amount. Obviously, none of the values are too big if the entire json blob is only 600 characters.

The server-side code is mine, so I can certainly change it to something easy to parse - like a comma-separated list. Seems like a shame to do that when the SDK is supposed to take care of converting data types to/from json. But if it's doing it in a really memory-inefficient way, I may not have a choice.

This is a data field, so perhaps there are very tight memory constraints (as opposed to apps/widgets). I'm testing on a Fenix 5X in the simulator, but I know the SDK documentation says the background process memory is even more limited than what the data field has available.

Are the background process limits documented anywhere? Anyone else run into this yet? Thanks...
  • Seems I am facing a similar issue of inconsistently running out of memory when using makeWebRequest. Wondering if anyone has found some solution?

    In my case, the transmitted data is below 100 Bytes of json in the request and below 100 Bytes of plain text in the response, yet I am inconsistently getting -102 BLE_reqest_too_large, -402 Network_reponse_too_large and -403 Network_response_out_of_memory errors. The data field is huge and uses more than 100K but the background process should be quite small using the (:background) annotation as it only passes data and the preparation of the request and the decoding of the reponse is done in the main process. 

  • When looking at memory, what you see at the bottom of the sim window is how much is used when your app is idle.  Use "view memory" in the file pulldown and look at peak.  I suspect you're getting really close to the max.

  • Jim - thanks for the advice. One of the difficulties I had was that the error occurred only on actual devices and never in the simulator. Added code to log free memory into the log files ... and for whatever reason now it seems to be working fine with about 1k plain text.

  • I had a similar problem. When receiving json data, I returned it raw Bg.exit (1219 bytes) - an OUT MEMORY error occurred even in the simulator.
    I solved this problem by parsing this data in the "onReceive" method, leaving only the necessary ones. Perhaps in the same method you can save this data using App.Storage.setValue.