-
• #2
Sure, just use
Modules.removeAllCached
. There's another function that'll just remove a specific module too. -
• #3
There may be a misunderstanding. I want to free memory.
Starting with this:var g = require("ILI9341").connect(SPI2,C6,C7,C8,function(){g.clear();});
Process.memory() returns usage 329
Dump shows var g = { ..... digitalWrite(C6,1....
Result is as expectedg = "";
Process.memory() returns usage 331
dump shows var g = ""; digitalWrite(C6,1.....
I expected less memory usageModules.removeAllCached();
Process.memory() returns usage 330
dump shows var g = ""; digitalWrite(C6,1.....
I expected less memory usage
Tried to do this:var b = "ILI9341"; g = require(b).connect(....
returns unable to read file no path
Process.memory() still returns usage 332
There is no object, no module, so how do I get rid of memory consumption ? -
• #4
No misunderstanding - I think there might be a bug in Espruino - I'll look into it.
If you try a different module it works as I suggested:
>process.memory().usage =17 >g=require("KeyPad") ={ ... } >process.memory().usage =61 >g="" ="" >process.memory().usage =62 >Modules.removeAllCached() =undefined >process.memory().usage =19
-
• #5
Great, just tested nightly build and it works fine.
What I'm doing now is to use something like this:
- copy my modules to sdcard in folder node_modules
- use require by variable not by string to avoid loading from WebIDE
clear modules after running my init procedure
var b,n; n = "myModule"; b = require(n).connect(...... // do a lot of functions b = ""; //to delete the object created during require Modules.removeCached(n); // do whatever is used after initialization
Next test will be to split an application into modules which are loaded and unloaded by a main application.
- copy my modules to sdcard in folder node_modules
-
• #6
Great! So are you actually running out of space, or is this 'just in case'?
By the way, you can also do
eval(require('fs').readFile("..."))
which might be slightly easier if you're loading specific bits of code.Espruino is designed so that it can 'page' variables and code out to flash - potentially giving it massively more available memory. It could be a fun project for someone :)
-
• #7
I ran out of memory by creating an extended module for ILI9341 and adding simple charts, so called "PicoChart". SPI.send ran out of memory during processing.
After restructering etc. there have been about 300 blocks left. Minimizing and some other changes brought it down to about 1000 blocks left.
Is there a way to free memory for unused parts, loaded with require ?
This could help for: