-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening and closing project cause memory leak #11
Comments
I have to try using that option more often. The game does indeed appear to be leaking objects somewhere. I suspect it is the AI, although I do not have a solid proof, nor any idea where it could do so. |
I have tried to reproduce this, but the results are not very satisfying. Running the editor itself with options mentioned did not result in any indication of memory leaks. Running an exported game with these options does indeed report some resources being still in use at exit (just like in the report), but this is not followed by the actual list of resources held. As to what may be causing it, I might have an idea. It seems that, if an object has a signal attached to another object outside of it's scene (for example to a global singleton handling mouse clicks or online communication), this scene might not get garbage collected when it's no longer needed, and potentially persist through exit. |
I do not think that can be the case. I have just tested it, and signal connections do not seem to count as references, at least for the purpose of RefCounted. Connected object simply gets destroyed and connection disconnected.
As for scenes, Nodes in godot do not get garbage collected at all. If you lose references to a node, it will persist in memory, causing a memory leak. That is called an 'Orphan node'. Nodes must be destroyed using |
I have fixed orphan nodes some time ago, checked with in-editor debugger and it didn't show any of these anymore. I don't know how the memory management works, but it is leaking somewhere. All you have to do is start a match and then keep hitting Restart mission button from ESC menu to grow the usage. It might be connected to the OP, or might not. |
In that case it's probably not related to nodes at all, since freeing the node forcefully dereferences it throughout the project. You might want to try forcefully freeing some other objects as well, like resources, instead of just dereferencing them. You shouldn't have to do that, but it might help you locate the issue. You can also try freeing important singletons one by one to see if that frees the leaked memory (You might need to leak a noticeable amount of it first). Might try literally calling If you free every single node in your tree and the leak still remains, then problem must lie outside the tree, which leaves godot servers, like DisplayServer and PhysicsServer3D. It's also possible that leak is not your fault at all, and is caused by some complex feature you are using. like generating textures through subviewports or something. |
Thats a lot of useful tips! I'll try that out when I have some time. From the list of things you mentioned I only use subviewport textures, and even that is very sparsely used. Overall this is not that big of an issue because the memory footprint of the game is low. Every reload adds dozens of megabytes, so a player would either have to play a LOT or savescum to even notice there is a leak. |
I just found out that GDScript does not handle cyclic RefCounted references This code immediately shows a huge memory leak:
Which is quite shocking to me. Apparently this is not even considered a bug, you are supposed to somehow use WeakRef to avoid such cyclic references. This fact complicates things a lot. Freeing singletons will not actually free such a leak. Though disabling chunks of functionality to narrow down the problem is still a viable method. Also using nodes instead of RefCounted makes situation easier, since they will be freed anyway. You might even consider inheriting Object directly and freeing it. It's more responsibility, but at least it gives guarantees. |
Opening and closing project with
shows this memory leak
I'm not sure what is cause of it
The text was updated successfully, but these errors were encountered: