+3 votes

In the documentation it is explained several times that _init ()is the name of the constructor, but what's the name of the destructor?
Is it anywhere documented?

in Engine by (692 points)

2 Answers

0 votes
by (7,946 points)

I expect that when you call free() member of a class it would call the destructor first and so then the destructor of the ancestor and so on.
The same way than _init() is called when you call new() with the class name.

_init has implicit "super" call, I don't know if is the same with free, you may need to do some tests.

But I think that the engine manages to free all the associated variables too, not sure if you need to override free at all.

+9 votes

The object receives the NOTIFICATION_PREDELETE notification through the _notification(what) callback. Check if the notification is NOTIFICATION_PREDELETE and react to it:

func _notification(what):
        # destructor logic
by (1,098 points)
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.