-
may not save you much memory at all (with removing a module from
Modules
cacheIn my case it was a lot of human readable data and thus quite verbose that gets binary-ized and stored in vars on execution of
require()
and beforesave()
- transformation from source data into runtime data - and the source is not needed anymore, nor the transformation function (and with the removal from theModules
cache I would expect the garbage collect collecting all, because nothing in runtime references anymore anything of this data in source format and it's related transformation function code.You're the first person to ever request something like that as far as I know.
In the spirit of Espruio's event driven-ness, I'm surprised... I would like to have something like that... because I do not want to put try/catches around the code or ask for error flag after execution/call of code that could set any of these flags, but it would be nice to be able to hold on / get notice of the even. It is good for monitoring that status / health of an app.
E.on(...,
is most likely the right place to hook in, because it is Espruino specific but not a hw pin / signal thing.
The errors that get reported are those from
E.getErrorFlags()
- generally they don't have much to do with the code that's running... For instance the 'out of memory' error is probably because something's being appended to an array - but it will rarely happen where the append itself is (more likely it'll be some other area of completely useless code).If it is an issue, you can still track it down by adding
E.getErrorFlags()
in your code, or even calling it from the debugger.It's the same error as before. It just doesn't also tell you that there was a filesystem error (which is a bit of a red herring if you have no SD card!).
Just do
Modules.removeAllCached
orModules.removeCached
once you haverequire
d what you need?However in many cases that may not save you much memory at all, since in JS a function has to have access to the scope it was defined in - so if you've kept any function at all, it'll stop that whole module from being freed.
Check out the
E.getErrorFlags
docs: http://www.espruino.com/Reference#l_E_getErrorFlagsYou get
'LOW_MEMORY'
- it's just that it isn't reported to the user, as in nearly all cases it doesn't matter.Potentially there could be an
E.on
event fired when the error state changes? I just wonder whether anyone would use it... You're the first person to ever request something like that as far as I know.