This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 Object.free() 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 Object.free() somewhere (such as _on_exit_tree) to ensure the application doesn't leave anything around?

Thanks!

Godot version 4.0.beta4.official
in Engine by (35 points)

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   
    return

1 Answer

+2 votes
Best answer

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

by (1,055 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.