i’m aware that not disconnecting them can cause memory leaks, but when should i actually disconnect them??
i’ve been told to disconnect them on the server, but not when i use a :Wait()??
I haven’t been told anything about the client, so i don’t really disconnect anything on there
i’m gonna go over some examples and ask questions regarding them
1 (server script).
local part = script.Parent
part.Touched:Connect(function(hit)
print("x")
end)
^ is something like this meant to be disconnected? or will this not cause any memory leaks?
this one is a remote event, but i also don’t know if i should disconnect that?
this gets called each time the remote event gets triggered, does this mean multiple of these fired in the span of x minutes will eventually cause performance issues?
You disconnect them when they are no longer needed, which is how you avoid memeory leaks, as they occur when things are not properly disposed of.
If you have something running in the background that has no use and is just sitting there taking up space, its best to remove it for new things to fill said space.
Overtime if things are not properly cleared, it will fill up your memory and evantually cause lag to your game.
:Wait() will yield until the event is fired, it doesnt create a signal like :Connect() or :ConnectParallel()
It doesnt matter if its the Server or Client, you still disconnect them to avoid Memory leaks.
i use a lot of those (and will have more), so i’d like to know if i should also disconnect the equipped (can you even do this without breaking anything inside your code??) and unequipped functions
As long as you are using them and disposing of them when they arent used, which if thats the case then yes, you would disconnect them for that purpose.
Lua has an intenal garbage collector that will remove anything has no longer has references, or is completely dead. If you dispose of the Objects that use the events, it will autkmatically dispose of those events.
Disconnecting things shouldn’t be done while things are currently using it, otherwise you will run into issues.