May a connection after script being destroyed/disabled still exists and cause memory leaks?

Hello. I would like to know if this one can cause memory leaks. I’ve tested it, and the connection still exists for some reason. I tried to disable/remove script, but nothing changed.

See below:

Is that because of bindable event, like i’ve linked it to that script i’m firing to? If yes, then how do i check in another way if connection was disconnected after script being removed/disabled?

1 Like

Long story short, yes. Disabling or deleting the script will not do much. You’ll need to use the RBXScriptConnection:Disconnect() method in order for it to truly get disconnected. Otherwise, I believe calling the Instance:Destroy() method on the instance which holds the event that you are creating a connection to will also force a disconnection (I am not certain of it, I still suggest explicitly calling the disconnect method)

Edit: I just checked myself, and destroying the instance will not trigger a disconnection. You need to explicitly call the disconnect method yourself :pensive:

3 Likes

This is very weird behavior, because while the script prints that it’s connected, the function won’t run if the event is triggered(as it shouldn’t). It’s only after the event is triggered again that the Connected property updates to false.

1 Like

Oh, god. My game has some scripts with tons of connections. My game basically uses regeneration where scripts being restarted by disabling and enabling them. I thought they would be disconnected after script being removed/disabled. As for now, i should find a way to clear all connections in scripts before disabling/removing it.

i assume, roblox should do something with that, otherwise this can lead to memory leaks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.