Homeyscript seems to have a memoryleak. Memory usage of homeyscript is growing very quickly after restarting the app or rebooting homey.
Memory usage grows very quickly to about 30MB and then it takes a few hour to grow furher to 75MB. Thats the point where Homey disables the app.
I have about 30 scripts. The scripts are simple. Most do only a fetch to a server. Even when there are no scripts executed memory usage is growing.
Are more people seeing this? Or maybe solved this? I am thinking about re-installing Homeyscript. But does that mean that i loose all scripts?
I have about 20 scripts, which donât get executed (mostly test-scripts) and I donât see any memory leaks. My first guess would be that the memory leak occurs inside your scripts, or perhaps within one of APIâs that Athom exposes. I will try some tests to see if perhaps fetch (which I assume you use) leaks memory.
const response = await fetch(URL);
const data = await response.text();
However, if you donât consume the body (i.e. donât use response.{text,json,blob}) it will leak memory. So always consume the body, even if you donât actually use it.
It doesnât really matter if youâre sending commands or receiving data, to prevent the leak (at least the one in HomeyScriptâs fetch) you have to consume the response body.
Hello @robertklep. I have changed all scripts but donât see any difference compared to the old situation. I have also written a small script to test but i donât think that fetch is my problem
async function execute() {
let counter = 0;
let total = 0
while(++counter < 200) {
f(counter);
await wait(1000)
}
}
execute()
During the test mem usage is around 40MB and does not change much. But over time (a few hours) mem usage is growing. Even at night when there are hardly any cals done to the service
In this test script i do a await response.text(); I see no difference between with and without this line of code
Have you tried commenting out the Homey.apps.getApps() part of your test to rule out that thatâs the cause of the leak?
Iâm afraid that when you keep seeing memory leaks, all you can do is turn off scripts (or rather, flows that execute scripts) one at a time to see if that fixes it, so you can track down if there is a particular script at fault.
Homey.apps.getApps() is only here for this test. I donât use that in my regular scripts.
Iâam afraid you are right, i have to go through all my scripts and disable one by one. One thing i could try before that is removing Homeyscript and reinstall it. But im not sure if i will loose all my scripts then. Do you have experience with that?
I experience the same problem. The homescript app pauses after a few days. I need to restart the app and it runs again (for a few days). Most of the scripts receives MQTT data every 5 seconds from my energy automation system, 10 variabeles in total. I switched from the logic variables to the better logic app but it does not solve the problem. Is it possible or necessary to unload local variables?
Edit:
I found a tip on a website about memory leaks and javascript.
Add as first row of the script: âuse strictâ;
Not yet sure of it is the solution, it take a couple of days before the app pauses again.
Hello,
Iâm gettin the same issue. I get temperature (1 sensor) and fan speed (4 fans) from MQTT every 5 seconds. I set a tags with that values and update virtual sensors values the tag values.
Very simple scripts:
So this issue still hasnât been resolved (in version 7.2.0 of Homey and version 3.2.6 of Homeyscript), which I find quite unacceptable. Homeyscript is Athomâs own app, and it should not leak memory by itself.
If my scripts were leaking, the memory consumption should be on a steady rise (scripts are called quite freqently, with just a few seconds between each call). It is not:
As you can see, it stays constant for almost two days, then suddenly eats a fairly large chunk of memory again.
And my scripts are extremely simple. Hereâs one:
// Converts received MQTT value in argument to a tag called ams_voltage
var number = parseFloat(args[0])
await tag("ams_voltage", number);
return true;
How can that leak any memory? It is just parsing an argument and writing it to a tag. I am not well versed in javascript, but I canât see how that could leak memory.