Is it good practice to use disconnect()
on functions wherever I can?
Itâs not vital, but itâs good practise. This prevents your game from consuming more resources than whatâs necessary, which can help overall server performance.
Only call connection:Disconnect()
when a connection is not being used, and are usually used on instanceâs that are not destroyed as âone time listenersâ or âtoggle- able listenersâ. You do not however need to call it if the object gets destroyed after itâs use as all connections tied to the object is disconnected automatically. And as the reply above stated, it is a good practice.
Will running :Disconnect()
on a function thatâs already been disconnected return any errors?
Yes, all you have to do to prevent this is: if connection then connection:Disconnect() end
Yes, actually it will.
In order to avoid errors, you can just do an if statement
check to see if the connection still exists.
local con
if con then
con:Disconnect()
end
:Disconnect()
is generally ran whenever a connection is not needed. You can save memory because you are cleaning up the connection and stopping it from unnecessarily using up resources.
Another thing to note here is that running :Destroy()
on an Instance
cleans up all connections that are connected to that Instance
.
Basically what you want to do with the Disconnect function is to garbage collect (The garbage collector manages the allocation and release of memory for an application. For developers working with managed code, this means that you donât have to write code to perform memory management tasks.)
You can use https://github.com/howmanysmall/Janitor or NevermoreEngine/src/maid at main ¡ Quenty/NevermoreEngine ¡ GitHub
No, providing the variable is still a reference to the RBXScriptConnection object (hasnât been set to ânilâ).