Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fatal Jerryscript Error: ERR_OUT_OF_MEMORY

ANSWERED

I am building a custom clockface where I need more than 500 static strings which I put in an JSON-array.
Stored on file without whitespaces the JSON-array is about 9KB in size.

I am now getting Fatal Jerryscript Error: ERR_OUT_OF_MEMORY

I guess this is because of the array, when I limit the array to a few elements only, the clockface is working in the simulator
.

So I am looking into alternatives of storing those strings in my clockface.
But before doing this I want to make sure I am not running into other memory constraints again.

1. Is there a way to deploy 500 files, like I can deploy images using the Resources directory?
I would like to create 500 files, each file storing a string and when creating the .FBA file I want the 500 files to be part of my clockface. Is that possible?

2. Instead of storing 500 strings in the JS code I consider to create 500 images with the strings already drawn and store those images in the Resources directory.
Is that even possible to store 500 images in the Resources directory? What are the storages limitations for apps or clockfaces?

3. What is the maximum memory a clockface (or an FitBit app) can handle?

4. Should I use the settingsStorage? What is the maximum size the settingsStorage can handle?

5. Do you have any other suggestions how to store 500 static strings in a clockface (or an App)?

Are there any memory differences between an app and a clockface?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

1. I'd probably try using localization to hold the strings.

https://dev.fitbit.com/build/guides/localization/

 

2. 15mb total size, including your code

3. 64kb

4. No, 5mb

5. See 1.

View best answer in original post

Best Answer
12 REPLIES 12

Although there are workarounds, i18n may be the best solution for you. Strings stored this way don't count against your 64kB Jerryscript limit.

Peter McLennan
Gondwana Software
Best Answer

Same problem . Used 16k of the 64k of Jerryscript memory. But ran out of memory with an array of 180*4 numerical and a file of the same size.

now I’m testing the system memory to see of I can find any solution.

Community Council MemberMario Dings | Rotterdam NL
Fitbit: Versa, Versa2, Sense. (Versa light) - Phone: Android. - Developer clockfaces.(Nederlands)
Best Answer
0 Votes

According to memory.js.used the footprint of my clockface is 29872 bytes out of 65528.
So how come I can't add the JSON array which is 9KB in size?

Best Answer
0 Votes

Check the memory level immediately before and after attempting to create the array.

 

Too many SVG elements can be a problem.

 

It is also possible to get a stack overflow, although that may give a different message.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I also have a suspicion that javascript stores strings as 16-bit characters (regardless of encoding).

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Not directly related to your problem, but may help - FitbitOS JavaScript Optimization Guidelines:

https://github.com/gaperton/ionic-views/blob/master/docs/optimization-guidelines.md

 

In most cases, you can assume one character in a string to be 1 byte. But it may as well be 2 bytes. Assume your average string length is 30 characters, 2 bytes each, 60 bytes per string, multiplied by 500, roughly 30 KB.

You can actually count it, see: 

https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder

https://stackoverflow.com/questions/5515869/string-length-in-bytes-in-javascript

 

Best Answer
0 Votes
Just made an array of 485 * 4 numerical. That did well. No so for the JSON I made of the array. Still testing. And changing my goals.
Community Council MemberMario Dings | Rotterdam NL
Fitbit: Versa, Versa2, Sense. (Versa light) - Phone: Android. - Developer clockfaces.(Nederlands)
Best Answer
0 Votes

If anyone wants to know how I solved my problem:
I created 300+ png-images with those 500 static strings prerendered and stored them in the resource directory. Size 2.2 MB. Instead of setting the .text property of a Text element I change the .href of an Image element instead. Not what I would have done in ASP.NET Core but it worked in the Jerryscript environment. One advantage is that I now can choose among my fonts from my Windows 10 computer when creating the text strings. One drawback is that app.fba is 4.23 MB in size and takes some minutes to install on my Fitbit Ionic. 

Best Answer
0 Votes

1. I'd probably try using localization to hold the strings.

https://dev.fitbit.com/build/guides/localization/

 

2. 15mb total size, including your code

3. 64kb

4. No, 5mb

5. See 1.

Best Answer

Are the strings all the same length?

 

9KB JSON would suggest they are only a few characters apiece

 

You could use a single string and pull the relevant parts out with something like

 

currentVal = buffer.substr(x*size,size)

 

Then it's only one string with one instance of string overhead

 

Regards,

Reign

 

Regards,

Best Answer
0 Votes

I needed an array of string arrays like this. Some indexes might have zero strings and some might have up to three strings. Depending on the index chosen I need to show zero, one, two or three strings in my clock face.
{
  "myArr": [
    {
      "N": []
    },
    {
      "N": [
        "Short string 1"
      ]
    },
    {
      "N": [
        "Short string 21",
        "Short string 20"
      ]
    },
    {
      "N": [
        "Short string 3"
      ]
    },
    {
      "N": [
        "Short string 42",
        "Short string 40",
        "Short string 41"
      ]
    } ...

Best Answer
0 Votes

Hello @GeekBit ,

 

Your test object is an array of objects containing an array of strings. Each level consumes memory.

Simpler objects consume less, sometimes far less. 

 

Example, an array of simple strings:

var myArr=["Short string 1",
           "Short string 21|Short string 20",
           "Short string 3",
           "Short string 42|Short string 40|Short string 41"
          ]
 
The result of myArr[3].split('|') is an array of strings: {0:"Short string 42",1:"Short string 40",2:"Short string 41"} 
 
The other problem with large arrays is that you often pay for them twice, once as javascript code, then again as an object in memory.
 
You can get around this by saving the object in a resource file once fs.writeFileSync("persist.txt"myArr"json") then read it as part of your initialization; fs.readFileSync("persist.txt""json")
 
Files consume device memory but don't consume the somewhat more limited javascript memory.
 
Regards,
Reign
ILuvChronoAnim.gif
Best Answer