Fixed server memory leaks#2097
Conversation
## Changes - Fix player connection cleanup in `Process.luau` - Cancel player load timeout tasks on leave - Clear `Remote.Clients[key]` on player removal - Fixed client folder staying referenced in server memory ## Why These changes prevent memory leaks which could impact the server on long uptime ## Testing Tested in Roblox Studio with multiple players joining and leaving. Confirmed that: - player specific connections are disconnected on leave - delayed load timeout tasks are canceled on leave - `Remote.Clients[key]` is removed on leave - client folder doesn't stay referenced after player leaves
| if Remote.Clients[key] then | ||
| Remote.Clients[key] = nil | ||
| end |
There was a problem hiding this comment.
I think the Remote.Clients[key] should only be dereferenced after a 1 second delay and it's confirmed that no player with the aformentioned UserId is in the server again (in case of quick re-join).
task.delay(1, function()
if not service.Players:GetPlayerByUserId(p.UserId) then
Core.PlayerData[key] = nil
-- move the Remote.Clients[key]=nil here instead?There was a problem hiding this comment.
yea i think that would be better
Co-authored-by: Wilson Simanjuntak <wilsontulus5@gmail.com>
ccuser44
left a comment
There was a problem hiding this comment.
Are you sure https://devforum.roblox.com/t/new-player-and-character-destroy-behavior-enabled-by-default/3161577 doesn't already handle the disconnection of events?
I do agree though that we should disconnect these events as a backup for multiple reasons but I'm not sure if we should utilize an indexed event list instead of a Janitor like pool of events & tasks to disconnect.
| Cleanup(plr, true) | ||
| end | ||
| end) | ||
|
|
There was a problem hiding this comment.
There are service specific connection handling stuff exactly for this kind of stuff so all of these indexed events and tasks should be made to use that functionality instead. Instead of having multiple local Connections = {} definitions.

Changes
Process.luauRemote.Clients[key]on player removalWhy
These changes prevent memory leaks on server which could impact the server on long uptime
Note
i made a pull before this one but i fucked something up and didn't see it
Testing
Tested in Roblox Studio with multiple players joining and leaving. Confirmed that:
Remote.Clients[key]is removed on leaveProof
before


after