I am trying to develop a game using Godot4.3 for HTML5. While testing the game on the web, I started getting a memory error after a certain period of time.
When I did some research, I came across the memory leak topic and checked all the objects I used one by one to find the error in my code. The strange thing is that when I try to find the memory leak using the debugger and monitor in Godot, all objects are deleted from memory after queue free as they should be. When I export and test on the web, the area occupied in memory continues to increase, although almost all objects are disabled.
My game is a 2D, bullet heaven, survival game. Even in a situation with only character, background and music, memory consumption keeps increasing. The character can’t shoot any bullets, he can only walk. The only thing that changes regularly is the clock text indicating the survival time. I also tried turning off the clock but again memory usage increased
Try testing older version of Godot (on simple project, to avoid breaking something).
For me web version 4.3 had horrible performance, so i switched back to 4.1.2 and it works smooth. Maybe some versions in between also work fine, i didn’t tested.
In my research on the internet, I read that version 3.x has better web export performance than 4.x, but I guess I can’t downgrade the codes I wrote in 4.x to 3.x. Will it be easy to switch from 4.3 to 4.1.2 or will I have to make major changes in the code?
Update: I tried to duplicate and open the project from 4.3 to 4.1.2, but it gave errors in many places. Now I am trying to clean the errors in the .tscn files, but dozens of errors appear. Is there an easier way?
It depends on project scale and individual quirks of engine version, but in my experience, swapping versions within major version always worked without any fuzz. Still, i strongly recommend do full backup of you project, before switching, or try on simple project beforehand (just to test if it helps with memory). All my projects where pretty small, and not used any plugins or external libraries.
I haven’t used any plugin either, but since I wrote all of my code using static typing, I think it gives errors about this in some places. I will try to solve it and write again. Thanks
I’ve been trying to downgrade from 4.3 to 4.1 and 4.2 for about 4 hours, but I think it’s not something I can handle.
Can you think of another option for the memory problem?
Too many compatibility issues, or it’s just doesn’t work?
I’m afraid that i can’t suggest better solution. At first, i accepted that this is how it runs in browser, switched to older version out of curiosity and was surprised by how much faster it performs.
Another way to “potentially” fix, is to upgrade to newer version, if it’s actually a bug and it got fixed. Right now you can test dev build 4.4.
Did you try to build simple project and test if the memory leak not happen in older versions?
The memory continues to increase even though I turn off everything that appears on the screen. I created a new Area2D and made it the main scene and exported it. It shows 1207 objects although there is no object on the screen. Where could these objects be coming from? If I can find them, I think I can find where the memory leak is.
Did you tried to reproduce memory leak on completely new project?
Hiding nodes does not disable them, only stop rendering, so _process and _physics_process still running.
Also, do you have anything in autoload?
Check how many nodes you have in debugging monitors during runtime.
I think I solved the problem. When I turned on Thread Support when exporting, everything worked as it should. Now I am dealing with cors and SharedArrayBuffer, but I think my memory problem is solved. Thank you for the answers