-
• #2
Isn't this a recursive call that will call itself until all memory is consumed?
(function lo(op){ console.log(incInput()); return sleep(5, function(){ return lo(op);
-
• #3
I guess no, since
sleep
(issetTimeout
under the hood) scheduleslo(op)
call and previous execution oflo(op)
ends there. Which means there is nothing related withlo(op)
function's execution within this 5ms duration. -
• #4
As setTimeout() is not necessarily ending a context... and that's what I think is going here, just as @Wilberforce says... it depends what arguments are passed with the sleep. If they keep holding on to a context in order to return at a later time, and the whole is nested - like parsing in a tree - it is easy to run out of memory.
Next thing is cross-compiling/generating: even though a powerful technique, it has its price... how is your sleep function look like?
-
• #5
Are you sure about that? Is it all because of this "recursive function"s memory consumption?
sleep
function is just a renamedsetTimeout
function:var sleep; sleep = function(ms, f){ return setTimeout(f, ms); };
-
• #6
Output a
process.memory()
in the loop and see if the jsvars drop. -
• #7
I reconnected the ESP8266 in order to add
process.memory()
in the loop and saw that it had been working for hours (11.25597 hours for now). I addedprocess.memory()
anyway:810428 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810429 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810430 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810431 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810432 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810433 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810434 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810435 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810436 { "free": 122, "usage": 1278, "total": 1400, "history": 1 } 810437 { "free": 122, "usage": 1278, "total": 1400, "history": 1 }
-
• #8
Well there's the first problem - you're walking on a knife edge there... only 122 free...
-
• #10
@DrAzzy After refactoring my classes (used
prototype
s instead), memory usage is decreased dramatically:41 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 42 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 43 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 44 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 45 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 46 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 47 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 48 { "free": 579, "usage": 821, "total": 1400, "history": 3 } 49 { "free": 579, "usage": 821, "total": 1400, "history":
Edit
...but this didn't entirely help solving the problem. I cycled the power supply many times. Most of the time it read from FlashEEPROM as expected (correctly), but at 10th time or so, here is the result:
Loading 7991 bytes from flash... Running onInit()... WARNING: Expecting a number or something iterable, got undefined WARNING: Expecting a number or something iterable, got undefined Error on unpacking: null wire data: ERROR CONFIG READ: Error on unpacking raw data read: dump: 1 WARNING: Expecting a number or something iterable, got undefined WARNING: Expecting a number or something iterable, got undefined Error on unpacking: null wire data: ERROR CONFIG READ: Error on unpacking raw data read: dump: 2 WARNING: Expecting a number or something iterable, got undefined WARNING: Expecting a number or something iterable, got undefined Error on unpacking: null wire data: ERROR CONFIG READ: Error on unpacking raw data read: dump: 2 error reading input counter: null ....
-
• #11
Here is the output after 30 power cycles:
Loading 7981 bytes from flash... Running onInit()... 299 { "free": 468, "usage": 932, "total": 1400, "history": 1 } ERROR: Out of Memory! WARNING: Truncating string as not enough memory Execution Interrupted during event processing. at line 1 col 127 ...[0]]=this.flash.read(t,r+4)),r+=t+7&-4,a=this.flash.read(4,r... ^ in function "readAll" called from line 1 col 24 var t,e,r=this.readAll();this.flash.erasePage(this.addr),t=t... ^ in function "cleanup" called from line 1 col 208 ...dAddr&&(r.end=this.cleanup(),r.end+e.length+4>=this.endAddr)... ^ in function "write" called from line 1 col 96 ...f.write(this.fileNo,pack(e)),sleep(3,function(){return Confi... ^ in function "write" called from line 1 col 83 ...return inpCounter.write(++n),n}catch(o){return e=o,console.l... ^ in function "incInput" called from line 1 col 22 console.log(incInput(),process.memory()),sleep(5,function(){... ^ in function "n" called from line 1 col 4 n(e) ^ in function called from system ESSID: aea ESSID: aktos-elektronik ESSID: Enopan trying to connect to wifi... {
The
Out of memory
error is thrown right afteronInit()
runs. How could it be possible?Edit
Program is not starting at all afterwards. Giving the following error:
Loading 7981 bytes from flash... Running onInit()... ERROR: Out of Memory! WARNING: Truncating string as not enough memory Execution Interrupted during event processing. at line 1 col 127 ...[0]]=this.flash.read(t,r+4)),r+=t+7&-4,a=this.flash.read(4,r... ^ in function "readAll" called from line 1 col 24 var t,e,r=this.readAll();this.flash.erasePage(this.addr),t=t... ^ in function "cleanup" called from line 1 col 208 ...dAddr&&(r.end=this.cleanup(),r.end+e.length+4>=this.endAddr)... ^ in function "write" called from line 1 col 96 ...f.write(this.fileNo,pack(e)),sleep(3,function(){return Confi... ^ in function "write" called from line 1 col 83 ...return inpCounter.write(++n),n}catch(o){return e=o,console.l... ^ in function "incInput" called from line 1 col 22 console.log(incInput(),process.memory()),sleep(5,function(){... ^ in function called from line 1 col 110 ...return n(e)})}(function(){}) ^ in function "sim2" called from line 1 col 44 ...mitFilter(),setupIo(),sim2(),sleep(1e3,function(){return con... ^ in function called from system WARNING: Truncating string as not enough memory Execution Interrupted during event processing. at line 1 col 127 ...[0]]=this.flash.read(t,r+4)),r+=t+7&-4,a=this.flash.read(4,r... ^ in function "readAll" called from line 1 col 24 var t,e,r=this.readAll();this.flash.erasePage(this.addr),t=t... ^ in function "cleanup" called from line 1 col 208 ...dAddr&&(r.end=this.cleanup(),r.end+e.length+4>=this.endAddr)... ^ in function "write" called from line 1 col 37 Config.f.write(this.raidFile,pack(e)) ^ in function called from system
-
• #12
It turns out that I had corrupted FlashEEPROM's
0x076000+1024
area with so many writes. When I get the object withnew require("FlashEEPROM")(0x077000)
, I can use this FlashEEPROM area.Now I changed the app code to use RAM, and flush very very rarely to the FlashEEPROM.
-
• #13
had corrupted FlashEEPROM...
Switch over to something that does not wear out THAT quickly... tha's why some IoT MC chip maker use non-volatile RAM so they can power off / down anytime without saving to (FLASH)EEPROM. See FRAM/MRAM - 256-Kbit (32 K × 8) Serial (SPI) F-RAM - Ferroelecric, non-volative RAM - SPI: something that behaves like EEPROM AND RAM at the same time. For your needs, a 32KB works just fine and runs with @DrAzzy's EEPROM lib... and with the same driver but without wait-after-write (and no page erase), it's even better... you can write and write and write... For 'production' runtime EEPROM may work... it got corrupted at development time because of the unusual high rate of retries... ;)
-
• #14
That sounds great! I could never think about that I would face with such a problem... Maybe we can replace original flash chip or add another one to the board on our next release.
-
• #15
There is a trade off... easy integrate-able FRAM/MRAMs are only both of smaller capacities and more expensive than (Flash)EEPROMs. With a huge (Flash)EEPROM compared to the space needed and the (Flash)EEPROM run on a wear leveling driver you do not run THAT quickly into issues. The MCs with FRAM/MRAM have only 16..128..256 KB of that type of memory and for the vast amount of read-only needs they still run (Flash)EEPROM. Having all your application state in transparent, non-volatile RAM makes a sleep and resume very simple and and even more so quick. Last but not least not having to save and restore state saves battery...
-
• #16
Worth noting that cheap EEPROMs (though not big flash chips) are readily available in I2C interface too, not just SPI.
Hi,
I have a relatively big codebase right now and I'm not sure what causes this error:
I guess I'm having trouble while reading from
FlashEEPROM
with the following class:Here is the Javascript output of above code:
I'm trying to use this code as follows:
...the Javascript:
The error is:
I expect the
sim2()
function to increment flash memory area by 1 in every 50 ms and this is what happens most of the time. But sometimes, (in a random order of power cycles) itConfig.read()
throws an error and memory can not be read.Is there anything I might misunderstand about usage of
FlashEEPROM
?