Comments (4)
Hi,
What you're seeing isn't a leak but is just the way Espruino works. Espruino contains a bunch of functions/methods but it can't keep those in a symbol table in RAM all the time because it'd use up memory.
Normally you access something from this list of functions in flash, it's momentarily in RAM, but then it's freed. But when you access something that's a member of something else, that first symbol table entry gets loaded into RAM. In this case what you're seeing is twofold:
process
gets loaded into RAM, when checking the memoryconsole
gets loaded into RAM, when printing
>process.memory().usage
=290
>process.memory().usage
=292 <----------------- here
>process.memory().usage
=292
>console.log("foo");
foo
=undefined
>process.memory().usage
=295 <-------------- console defined now
>console.log("foo");
foo
=undefined
>process.memory().usage
=295
You can set console
to undefined
as you note, but actually you've still got a variable called console
which is set to undefined
(so one var). You could remove it with delete
completely and free the memory though (although this is kindof non-standard).
I'm happy to add a note about this behaviour as yes, it can be a bit confusing. Where exactly would you have expected to see info on this? In Testing Afterwards
on https://www.espruino.com/Bangle.js+Fast+Load ?
from espruino.
Hi @gfwilliams, I had a feeling that's what was happening :)
Since this is expected behavior, I think there should be a section underneath "Other libraries", maybe called "Other symbols/builtins", which explains these expectations. I think it would also be best to show examples of how to determine if this is happening in your own app.
For context, I am working on a fork of Anton Clock and wanted to make sure I didn't cause any memory leaks (while allowing Fast Loading). Turns out that Anton Clock has (what appears to be) the same memory "leak" that I do. The supposed leak is much larger than these 3 blocks we are talking about above, and I am confident that it doesn't have anything to do with console
specifically, but it leaves me questioning. What I really need answered by that page is: how can I be positive that my app isn't leaking memory, and that any leftovers are expected? Checking the module size with E.getSizeOf(global["\xff"].modules)
is a good example of the kind of procedure I would want if I was trying to find out whether I have an unexpected memory leak at all. I'm still not sure if my app (or Anton Clock) actually is leaking memory unexpectedly, or if this is all well-defined behavior.
In conclusion, it would greatly benefit devs like me if any additional known caveats to the debugging procedures in the Fast Load instructions were documented there clearly, with concrete steps that will prove whether you have an unexpected memory leak (since right now, a lot of the phrasing on the page leaves you feeling uncertain).
from espruino.
Also, follow up question: can I still take advantage of Fast Load if I call Bangle.setUI()
twice in my app? The first one shows the watchface, and the second one shows a different "screen" of the watch. Unfortunately, when the second one is called, it runs the remove
function I provided in the first one, which should clean everything up, which means that some resources are no longer available. So it seems like you can't have a clock that calls setUI()
more than once and allows for Fast Load. Is that correct?
from espruino.
Ok, cool - I'll add something.
The easy way to check for leaks (which I'll document) is to run your app more than once by repeatedly flicking between the loader and the clock. After the first time a few things (like console
) would be allocated, and maybe the launcher would do something too, but after you've done it a few times you shouldn't be seeing the memory usage rise any more.
can I still take advantage of Fast Load if I call Bangle.setUI() twice in my app?
Yes - so you're right that remove
is called and that should remove everything global, but you don't have to worry about 'local' variables (eg. defined with let
inside a block {}
):
{
let myVariable = { ... };
let myVariable2 = { ... };
function changeToScreen1() {
Bangle.setUI(...);
}
function changeToScreen2() {
Bangle.setUI(...);
}
changeToScreen1();
}
Anything inside that block can use myVariable
, and you don't have to delete it when remove
is called. You can swap between different setUI
and remove will be called and should clear up, but you don't have to worry about myVariable
since as long as no function defined in that scope it is used by Espruino after you've cleared up, it will be freed automatically.
from espruino.
Related Issues (20)
- Wifi.connect(ssid, options, callback) does not handle callback HOT 2
- Multiple uploads of code with wifi command can cause " New interpreter error" HOT 1
- Debugger feature: add backtrace command HOT 2
- E.getPowerUsage to estimate power consumption HOT 2
- BLE/NRF and esp32_gatts_func.c HOT 1
- Promise handling rewrite break BLE device use HOT 3
- ESP32_IDF4 (ESP32C3) support HOT 4
- Any plans to switch to python3? HOT 6
- `Object.defineProperty(<function>, ...)` HOT 1
- `Object.clone()` returning function HOT 2
- Using different pins for neopixel on ESP32 does not work correct HOT 6
- Loss of errors when executing require() HOT 4
- banglejs_iflash build: error running `.bootcde`, compacting corrupts `.boot0` and deletes most files HOT 4
- Static fields in classes HOT 1
- Bad text alignment when rendering Unicode centered
- overlays are cut off from the top instead of landing at desired y position HOT 2
- [Bangle.js 2 Question] EXTCOM frequency HOT 1
- nrf5x_dfu/main.c highlight potential impossible code path HOT 2
- Scoping bug when defining a function from a previous scope HOT 14
- Stuck uploading firmware v23 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espruino.