You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Ahh, ok - that's tricky. I didn't realise it was Espruino WiFi.

    The Espruino WiFi is a bit oddball in that it only has one page for storage - a 64kB one - so there are no 'unused' pages it can free. If it can't get the contents of that page temporarily into RAM then it can't compact it.

    If you try:

    var s = require("Storage");

    It should show you roughly how much space is needed for each file. My guess would be that ".varimg" is using by far the most.

    By default it'll try storing the data that's needed on the stack, but that's probably only around 10k or so, and I bet .varimg is more than that.

    What you could try doing is:

    function tryCompact() {
      var s = require("Storage");
      var x = E.toString(".varimg"));
      if (x===undefined) throw new Error("Not enough RAM for varimg");

    Which will try and allocate space for .varimg as a JS variable (rather than on the stack), will then remove it from storage, compact, then write it back. That might work?

    Otherwise .varimg is an image of what is in RAM when you save, so another slightly scarier option is to do:

    save(); // but this will then reboot the Espruino WiFi

    But hopefully you should only ever have to do this when the WiFi board runs out of storage.

    Or... It looks like you're basically dynamically loading JS code? If that's the case then you probably don't need to use save() at all - you probably want to use the save to flash option in the IDE to save just a simple 'bootloader' that searches for init/etc and runs them in sequence?

    If you did that then you wouldn't need a .varimg file, and chances are compacting would go fine.


Avatar for Gordon @Gordon started