Ticket Created
over 4 years ago

WERETECH-9896

Memory fragmentation in FW?

My long running app crashes and I suspect memory fragmentation in the FW.

It ran for 1:45 on my F5 before crashing out of memory: 

Error: Out Of Memory Error
Details: 'Failed invoking <symbol>'
Time: 2020-10-17T02:18:02Z
Part-Number: 006-B2697-00
Firmware-Version: '20.00'
Language-Code: eng
ConnectIQ-Version: 3.1.9
Filename: RACEQS
Appname: raceQs
Stack: 
  - pc: 0x30000e9b


Note that the location 0x30000e9 is well outside the memory addresses of my code.

I'm monitoring the memory usage at the start of each GPS location cycle and it is steady at around 102 kB.

The crash occurred independently of any user input: it was running fine and then, a few minutes later when I next looked at the watch, it had crashed.

I have run the app twice through the simulator using the FIT file generated in the original session, as far as possible performing the same user inputs as on the original session. The memory usage remains around 105kB. The peak memory remains firmly at 117.5kB.

It peaks at the start of the app when it downloads a large data file containing the race courses and rounding marks.

I have had a  small number of similar reports of out of memory errors via ERA on a range of devices:  Forerunner® 245: 5.00, vívoactive® 3: 7.40, all reporting memory crashes, but all at different code locations.

This behaviour indicates, and I say this with much trepidation after many decades of software development, that the issue is not with my code, but with the underlying firmware, operating system or hardware.

Given that it only occurs sporadically and in my test, only after a long period of running (1h 50 mins), I wonder if it is being caused by memory fragmentation in the FW?

And if so, what can I do about it?


P.S.I had a similar problem on this platform a couple of years ago and discovered the fault was with my code: I had a hierarchy of menus and was not Popping them correctly. At the time, the simulator behaved differently and did not show my memory leak. Since then, I am logging memory usage at the start of each GPS callback to capture any such oversights. 

  • Yes, I know.

    I am not adding to any arrays or growing strings. 

    I am updating, not adding to, my big array every second, just holding the latest 120 seconds of data using an index to manage a cyclic buffer.

    And anyway, if I were adding to array or building strings, it would show up with the way I'm monitoring memory: as I said, in live running, I am monitoring memory each GPS cycle (1Hz). It remains steady at around 102kB.

  • One thing I'd look at is how you handle data. 90 minutes in the sim really isn't that long, and I'd try something much longer, more like 8 hours and see if it breaks in the sim.

    One place it might not be clear how much memory you need at times is with arrays. (there are others)

    Lets say you have an array with a size of 2000, and every minute you do myArray.add(newvalue)

    What actually happens, is that memory is allocated for an array of size 2001 (with a huge array, enough memory could be an issue), the old data is copied over, and then the old array is freed.  So for a brief time, it's like you are using the memory of an array that's more than twice as long.

    The same thing happens if you grow a string.