Hey Everyone! Thank you for your help, here’s my doubt:
If I populate a GUI by iterating a dictionary, Cloning
a GUI button per iteration and placing it inside a GUI container then Connecting a function to each button that is created from the loop, When I ClearAllChildren()
from that GUI container deleting all those buttons, does the Connected functions still exist or get deleted?
Or should I disconnect all those fuctions too?
I found many scenarios where I must build a table of connections created and iterate it to discconect all of them, should I use the same approach for a GUI? or when the buttons get “flushed” by ClearAllChildren()
all those connections gets deleted too?
1 Like
:ClearAllChildren()
appears to behave identically to calling :Destroy()
on all children of an object; as such, your events should get disconnected automatically by the engine and you should be good to go.
2 Likes
I cant remember when something like this did happen:
ClearAllChildren()
with a folder with scripts, didnt disconnect the functions running there. Apparently were still running from the memory…
And I found a post in DevForum, talking about that ClearAllChildren() sometimes it doesnt totally removes it from memory, like “no garbabe collecting”
Anyway, but I think the same as you, after deleting the buttons the engine disconnect the events. But nothing still on memory?
If not, its perfect! Thank you so much for you reply
Destroying scripts is a little tricky. If they are in-process of executing a thread (like in the case of an endless while
loop or something), destroying or disabling them seems to be ineffective; interestingly enough, however, it seems that doing either of those things does still disconnect their event listeners even if their main thread keeps running.
If you are just destroying non-script objects, though, there should be nothing to worry about unless you’re holding references to the objects/event listeners elsewhere in your code. In that case, they will still be destroyed/disconnected, but they won’t get collected. That is the case regardless of what method you use to destroy the object.
1 Like
Thank you so much, that clarifies many things I experienced!