Is it wrong if a signal cannot reach its target function?

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

Hello! To summarize, I am calling a function at the end of an animation, using this code:

var animLenght = exampleAnimation.CurrentAnimationLength;
GetTree().CreateTimer(animLenght).Connect("timeout", this, "exampleFunction");

However, this script belongs to a scene that can be freed at any moment. So it could be that the timer would continue and eventually emits the “timeout” signal which will try to access a non existent script, therefore a non existent function, in the running scene.

It doesn’t returns any error, but… Could it be, as it would be the case when using async functions, that something is left opened and would leak memory?

Thank you for your time.

:bust_in_silhouette: Reply From: zhyrin

When you emit a signal, godot checks if the receiving object still exists, but it doesn’t seem to delete the connection if the receiver has been freed.