-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
GDScript
resources are not unloaded due to an extra reference
#77513
Comments
It's by design to enable cyclic references. Each GDScript loaded has a Ref instance living here: godot/modules/gdscript/gdscript_cache.h Lines 79 to 81 in e188d61
But the garbage collection part is not yet implemented, unfortunately. |
Does this mean that |
I believe we talked about this in the chat but let me register here as well for the record. The cache should not be keeping extra references to scripts. It's fine if the scripts themselves are in a cycle, since that is unavoidable (and where a cycle collector would be handy), but in the case there are no cycles the scripts should be naturally freed. Scripts sometimes preloads scenes which can get quite heavy so keeping them in memory can ended up with a lot of used space which is not obvious where it comes from. Without the collector it's much worse because there's currently no way to unload scripts. So this needs to be addressed. I do plan to work on this (probably next month if nobody beats me to it). I've also notice some other issues with the cache, like keeping non-compiled scripts as if they were compiled which gives another sort of problems. |
I agree. I was the one that modified the cache to make it so that it keeps an extra reference to the script. But the reason why references are kept in the cache is because a script reference count would drop to zero even before having the opportunity to cyclically reference itself. So if we're able to fix that issue, I'm all in to drop these references. Maybe we could try to store the refs shallow scripts, but once a script is fully loaded, only cache the pointer (not a ref of a script). |
Looking forward to any progress on this👀 |
Godot version
v4.0.3.stable.official [5222a99], master
System information
Kubuntu 23.04
Issue description
It looks like we have an extra reference to the script somewhere, which prevents it from being freed at the right time.
See also the comment.
CC @adamscott
Steps to reproduce
Minimal reproduction project
bug-script-ref-count.zip
The text was updated successfully, but these errors were encountered: