The memory used isn't continuous, but that's by design and not too much of an issue.
It's more that with JS you have this idea of an execution scope. So take this example:
function a() {
var b = 42;
return function() { return b; };
}
getB = a();
getB(); // returns 42
The getB function isn't just function() { return b; } - it contains a pointer to the 'execution scope' of a so it can access the value of b.
So in this case, E.getSizeOf(getB) returns a value much bigger than E.getSizeOf(function() { return b; }). It makes some sense here, but when you get to bigger projects, it can make it difficult to find out where your memory is actually being used.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The memory used isn't continuous, but that's by design and not too much of an issue.
It's more that with JS you have this idea of an execution scope. So take this example:
The
getB
function isn't justfunction() { return b; }
- it contains a pointer to the 'execution scope' ofa
so it can access the value ofb
.So in this case,
E.getSizeOf(getB)
returns a value much bigger thanE.getSizeOf(function() { return b; })
. It makes some sense here, but when you get to bigger projects, it can make it difficult to find out where your memory is actually being used.