Darnoman / Godot-GlobalInput-Addon

MIT License
13 stars 3 forks source link

The addon causes memory leaks #6

Closed MudkipWorld closed 3 weeks ago

MudkipWorld commented 3 weeks ago

Hi, hope I am not annoying you with another issue 😅 I got someone to test my PNGTuber app, they noticed a massive memory leak to the point the app on their side crashed due to memory overflow. I decided to look into what is happening, I noticed when my mouse was inside the app window and mainly moving around, the Object counter in the monitor rises so fast, but almost never goes down :

https://github.com/user-attachments/assets/0f17bb8f-7e55-4880-81d0-b46b845b9315

I know this is due to the addon because I decided to make a completely new project with this addon only, no other code, just an empty scene with a Node2D and yeah, same strong rise of objects counter happens too. Made extra sure by removing it from my project and no leaks!

I hope you are able to fix this ^^; Take your time tho, I can wait

Darnoman commented 3 weeks ago

Dw your good lol. It's nice to have a project using this as it catches bugs that I wouldn't have caught otherwise. I'm not the best programmer so idk how long it'll take to solve this issue. But I'll try my best.

MudkipWorld commented 3 weeks ago

Thanks for not minding me opening another issue! Good luck with trying to fix the issue too

Darnoman commented 3 weeks ago

Alright a way that I'm solving this is by removing GlobalInput's methods and it's whole independent dictionary system from Input's InputMap. This new way would allow you to just use Input's methods. I'm able to do this through Input's parse_input_event method. This way it shouldn't create any new dictionaries/objects (hopefully) and would be compatible with code just using Input.

MudkipWorld commented 3 weeks ago

Sounds good, if you want me to help in testing and debugging it, I don't mind to, feel free to tell me

Darnoman commented 3 weeks ago

the update has been pushed to the v2 branch

Darnoman commented 3 weeks ago

I also updated the original SharpHook branch. I added GC.Collect(); at the end of _Input() and it looks like it fixed it. Idk what was causing the memory leak, but it seems like that fixed it.

MudkipWorld commented 3 weeks ago

Good to hear you were able to fix it. Honestly, since I am not too familiar with c#, idk what caused the leak too.. kinda From what it seems, tons of objects were slowly being created overtime without being removed, causing the leak. I myself didn't even know that was possible xD Will consider this a done issue for now, feel free to open it if someone else reported another leak!