Which is the destructor function of a class?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By genete
:warning: Old Version Published before Godot 3 was released.

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?

:bust_in_silhouette: Reply From: eons

I guess it should be free().

http://docs.godotengine.org/en/stable/classes/class_object.html#description

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.

genete | 2017-02-02 23:29

_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.

eons | 2017-02-03 02:44

:bust_in_silhouette: Reply From: eska

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):
    if what == NOTIFICATION_PREDELETE:
        # destructor logic
        pass