Do persistent Objects need to be freed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AdamActual

Hi all,

Sorry for the basic question. I have some data classes that inherit from Object, are created at the beginning of the game and never destroyed.

The documentation says that should be called for Objects to avoid memory leaks. Am I correct in believing this isn’t necessary if the Object is never actually removed?

Basically, does the application automatically delete everything when it’s closed? Or do I need to call somewhere (such as _on_exit_tree) to ensure the application doesn’t leave anything around?


Very good Question dude, hope you get it answered.
Godot boasts about its garbage collection and recommends using Reference (Think its called something else in Godot4) instead.

For me personally can’t get the C way of having to do everything yourself out of my system and always do

func foo():
    var array = Array()
    # use array here
    array = null   

Wakatta | 2022-11-07 16:46

:bust_in_silhouette: Reply From: SteveSmith

All objects will be “disposed” when the program is closed. The OS will make sure of this.

To slightly expand on this, operating systems will reclaim all resources when a program exits. Any existing Godot objects that haven’t been properly disposed will just cease to exist upon program exit, just like in any other language.

stormreaver | 2022-11-08 16:33