• Storage.read docs agree with wath you say: "This function returns a String that points to the actual memory area in read-only memory, so it won't use up RAM."
    Most likely what you do next uses all the memory. Here is an example that creates a 1000 long file, read-s it, and free memory doesn't decrease by a lot (CPU is bare nRF52832, same as in the Bangle):

    >var st = require('Storage')
    =function () { [native code] }
    >process.memory()
    ={ free: 2466, usage: 34, total: 2500, history: 8,... }
    >
    >st.write("a","Hello",0,1000);
    =true
    >var readback = st.read("a")
    ="Hello\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ... "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
    >process.memory()
    ={ free: 2463, usage: 37, total: 2500, history: 19,... }
    >readback.length
    =1000
    >process.memory()
    ={ free: 2463, usage: 37, total: 2500, history: 22,...}
    
    /// write some at the end, and read back a slice of it:
    
    >st.write("a", "Hello at the end", 1000-16);
    =true
    /// the last character:
    >readback[999]
    ="d"
    >readback.slice(1000-16, 1000)
    ="Hello at the end"
    >process.memory()
    ={ free: 2455, usage: 45, total: 2500, history: 45,...}
    

    You can force it to take up memory by slicing into it for example:

    >var thisIsInMemory = readback.toString()
    ="Hello\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ... "\xFFHello at the end"
    >process.memory()
    ={ free: 2445, usage: 55, total: 2500, history: 61,... }
    >var thisIsInMemory = readback.slice(0,1000)
    ="Hello\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ... "\xFFHello at the end"
    >process.memory()
    ={ free: 2361, usage: 139, total: 2500, history: 66,... }
    >var thisIsInMemory2 = readback.slice(0,1000)
    ="Hello\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ... "\xFFHello at the end"
    >process.memory()
    ={ free: 2275, usage: 225, total: 2500, history: 71,...}
    >var thisIsInMemory3 = readback.slice(0,1000)
    ="Hello\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ... "\xFFHello at the end"
    >process.memory()
    ={ free: 2189, usage: 311, total: 2500, history: 76,...
    

    On each invocation memory decreases by 86 vars, and the 12 byte of string per jsVar int the Performance section.
    86*12 = 1032, there is a bit of overhead for history and storing the actual variable.

    You can also try readArrayBuffer if you want to work with binary data. That doesn't eat up memory right away either:

    >var ab = st.readArrayBuffer("a")
    =new Uint8Array([72, 101, 108, 108, 111,  ... 101, 32, 101, 110, 100]).buffer
    >process.memory()
    ={ free: 2186, usage: 314, total: 2500, history: 80,...}
    > 
    

    Oh, and you can get the size of things:

    >E.getSizeOf(readback) // returned by `read`. Just a reference to flash
    =1
    >E.getSizeOf(ab) // returned by `readArrayBuffer`. Just a reference to flash
    =2
    >E.getSizeOf(thisIsInMemory) // this is a string
    =84
    
  • Here is an example that creates a 1000 long file, read-s it, and free memory doesn't decrease by a lot (CPU is bare nRF52832, same as in the Bangle)

    So you didn't use Bangle when trying this? There may be another issue that Bangle uses external SPI flash for storage (?) which is not directly mapped to cpu address space so data needs to be loaded to ram at some point.

About

Avatar for AkosLukacs @AkosLukacs started