Will variables become nil if its connected to an event and you disconnect the event?
No, the same happens with the destroyed instances, it is stored in the variable
What if we make the connection nil afterwards? will it nil the variables what can I do to make all the variables nil in the connection
If you put the variable as nil
without disconnecting the function it will remain connected, the correct thing is to disconnect the connection and then place it as nil
, so the garbage collector can clean up the memory it used.
I have a long list of variables that need to be set to nil, what can I do to nil all of them.
I’ve done the above but what what if you had instead of print(“Heya”)
it was
local Variable = script.Something
Connection:Disconnect()
Connection = nil
print(Variable)
You may want to look into maids. There are a bunch already created that work really well for this sort of stuff.
Maids basically are used so you can do something like this
Maid.Variable = nil
Instead of
Variable:Destroy()
-- or
Variable:Disconnect()
Variable = nil
They aren’t essential but they handle the gc so you don’t have to.
Yes will look into maids thank you, as well but for the time being I need to just know are variables INSIDE connections set to nil after the connection is set to nil.