ags icon indicating copy to clipboard operation
ags copied to clipboard

memory leak?

Open Xtr4F opened this issue 1 year ago • 6 comments

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.

Xtr4F avatar Aug 22 '24 20:08 Xtr4F

P.s.s. At the time of writing this issue, ags crashed with an error, filling about 770mb of memory, lol: image

Xtr4F avatar Aug 22 '24 20:08 Xtr4F

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

Xtr4F avatar Aug 22 '24 21:08 Xtr4F

does printing the output directly (without passing into the json parser) trigger the GC?

might be a leak in the JSON parser

its-darsh avatar Aug 23 '24 22:08 its-darsh

No, it doesn't. And memory leak happens only with Utils and Services methods like Utils.exec, Utils.execAsync, Utils.fetch , hypland.message, etc

Xtr4F avatar Aug 24 '24 17:08 Xtr4F

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:

pic

It really seems to be a problem with some parts of Utils and Services 🤔

Xtr4F avatar Aug 25 '24 21:08 Xtr4F

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

Xtr4F avatar Aug 26 '24 08:08 Xtr4F