Repeated Comm.makeWebRequest calls causes out of memory exception

I have an app where i call a REST service once every second. At first, when the response only contained two values the app ran just fine. But as I added more values to the response I started to get out of memory exceptions. Right now the response holds four values and the app crashes after five minutes, when it only had three it ran for two hours.

Might this be due to a memory leak in the makeWebRequest or are there any other known issues in that API?
  • What happens if instead of doing the call once a second you do it once every 5, 10 or 15 seconds? Or maybe hold off on doing a request if you're still waiting for the response from the previous request?

    One second for BT->phone->inet->phone->bt->convert to dictionary could be a bit too fast, and it might be there is a "pileup", resulting in higher memory usage, and the error. (Things happen MUCH faster in the sim than on a real device)
  • Thank you for your reply.

    I've already tried to hold off on the next call until the response is recieved, but that does not seem to help. If i change the interval to 5 sec it still crashes after the same number of calls as it did when the interval was 1 sec, it just takes a bit longer to get there :) The thing is, I want the app to update the data as often as possible.

    Regards
    Jonas
  • What device or watch are you using? Does it happen in the sim? What version of the SDK are you using?

    How close to max memory are you? You could include Sys.getSystemStats.usedMemory to see the value on a device, and in the sim, keep an eye on Peak memory on the bottom line of the window. (could it be that your app is using memory between calls and that's chewing into memory needed by the call?)
  • It happens in the sim and on my FR 630. It runs for a longer time on the watch, in the simulator it dies within the minute. But maybe that's because things, as you said, runs much faster in the simulator. I'm using SDK version 2.1.2

    If I remove all the logic for processing the response, it still fails on out of memory. So that part of the code should be ok.

    The app is quite big, it starts out on 53/57 (mem/peak) and the FR 630 has 64 available. That gives me about 40 calls before it runs out of memory.
  • I edited my last comment and asked about memory. What do you see in relation to that?

    If you comment out the actual call but repeat everything else on a time basis, do you see the memory usage increasing? (I'm thinking maybe your app might keep using more memory itself, leaving less and less for the call)
  • If you comment out your code for onReceive(), the FW/VM is still having to handle the response. What if you comment out the makewWebRequest() itself? Does "peak" increase?

    Starting at 57k peak is quite large. How much of that do you use for data vs code? You might needs a better way to manage your data if that's a big part of the 57k.
  • If I comment out makeWebRequest the app runs fine, memory consumptions is stable 53.7
    The data size in the response is only 295 bytes, so there should at lease be some space left.
  • Does Peak also stay stable? (the "memory" number is when your app is idle, so it may not change much - "peak" is better at what your app actually uses - using Sys.getSystemStats.usedMemory in a few places in your code can help to narrow down where the higher memory usage occurs)
  • Yes, peak also stays stable. This is a print out of memory consumptions just before the app crashes:
    [table="width: 200"]
    [tr]
    [td]before request[/td]
    [td]62056[/td]
    [/tr]
    [tr]
    [td]after request[/td]
    [td]62104[/td]
    [/tr]
    [tr]
    [td]handle response[/td]
    [td]61032[/td]
    [/tr]
    [tr]
    [td]before request[/td]
    [td]62568[/td]
    [/tr]
    [tr]
    [td]after request[/td]
    [td]62568[/td]
    [/tr]
    [/table]

    The weird thing is that memory goes down in my handle response function, but then goes up again before i make the next call.
  • You're at the point of memory usage that I'm guessing what you're seeing is a result of that.. Too close to the 64k for me.

    What you might try, just as a test, is use the 735 as a target in the sim instead of the 630. It allows apps that are 122k, so it might help to see what's going on.