Godot Version
v4.4.stable.official [4c311cbee]
Question
Hello,
Over the years, I’ve built up a collection of helper files containing classes with numerous static functions.
I carry this personal library across projects, though I don’t always use every function.
Are there any drawbacks to having many static functions rather than encapsulating these helper classes in instance variables as needed?
Are there any drawbacks to having many static functions rather than encapsulating these helper classes in instance variables as needed?
None that I can think of. I have the same kind of library, and I never had any problem with it.
The only drawbacks you may have are related to the static classes and methods drawbacks themselves. Like not being able to override, for instance, but it’s probably not something you want to do, based on what you’re explaining.
Anyway, the workflow you’re using seem perfectly fine to me. Not a Godot expert nor a senior developer, but I’ve been working on a few shipped games and all of them had a library made of static methods, a lot of them being unused. Just here in case.
Thank you for the response!
I recall reading that RefCounted
objects (the helper files in my case) can be tricky and might sometimes linger in memory instead of being automatically freed in certain edge cases—but I could be misremembering.
Oh, I thought you were talking about simple static classes and methods. RefCounted
is a different topic than static classes/methods.
As the documentation says:
Unlike other Object types, RefCounteds keep an internal reference counter so that they are automatically released when no longer in use, and only then.
So yes, there may have been leak issues in the past. Also, in C#, the garbage collector is responsible for freeing RefCounted
objects.
I think the documentation explains those things well, so maybe have a quick look at it. I’m not so used to RefCounted
so I’ll let anyone more seasoned answer too and correct me if I’m wrong. 
Yes, I forgot to mention that all my static functions are part of RefCounted
classes
I do this because it allows me to easily call functions using the class name + function name without needing to store them in autoloads…
1 Like
The object is probably still never created, you could extend Object
to be even more sure. Still one RefCounted/Object won’t break the bank, and in Godot’s source and GDExtension most singletons are extending Object.
1 Like