Topic was automatically imported from the old Question2Answer platform.
Asked By
genete
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?
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.
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