memory leak?
RAM usage is growing uncontrollably when using Utils.interval. it looks like it's a problem with hyprland.messge() (and .messageAsync() as well, which is causing this to happen. I've tried using Utils.exec() alternatively and haven't noticed this behavior. Video below:
https://github.com/user-attachments/assets/70a87d41-3bef-48b4-8666-6df4a5a27275
P.s. 1 millisecond interval for clarity. In reality, even with interval values like 100, memory usage grows, just a bit slower, but it is never freed, even when the interval is already destroyed.
P.s.s. At the time of writing this issue, ags crashed with an error, filling about 770mb of memory, lol:
So, I did a little investigation (ran 4 different ags instances with different interval times, the first two with 5ms, the last two with 50ms. The first and third call hyprland.message, the second and fourth call Utils.exec) and it turns out that all of them increase memory usage over time for some JavaScript reason I don't understand, just at different speeds:
But now I'm even more confused as why in the world this is happening?
Well ok, in many cases it's not that critical since you won't run it infinitely, but the problem is that it doesn't free memory even when the interval is destroyed (or I'm doing something wrong, I'm a noob in JS), which can already lead to some bad consequences
does printing the output directly (without passing into the json parser) trigger the GC?
might be a leak in the JSON parser
No, it doesn't. And memory leak happens only with Utils and Services methods like Utils.exec, Utils.execAsync, Utils.fetch , hypland.message, etc
upd. The only solution I've come up with so far is to use an external script. But Utils.subprocess() also causes a leak. So I use Variable instead. And for some reason it works fine. I left this code running for about an hour and RAM usage never once went over 60mb:
It really seems to be a problem with some parts of Utils and Services 🤔
What's even weirder is that I have looked at the sources and Variable also uses subprocess but doesn't cause this problem:
https://github.com/user-attachments/assets/f9ddbbf6-20cc-4450-9c10-629bbd477d3e