Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Do I have to worry about garbage collection on the client when the player is leaving?

This question is pretty straightforward, and I'm asking it just to be safe. Is there any reason to do garbage collection on the client as the player is leaving the game? For example if a local script is running on the client tracking playerdata, should I worry about ending that process as the player leaves the game?

2 comments

0

But why did you unaccept my answer over a shorter less explaining

0

I thought his answer was more descriptive for the part that answers my question. You're answer has some extra info that is also useful tho so I still gave a thumbs up. I think a mod accepted ur answer or something in the first place bc I hadn't even read it when I saw it was accepted

2 answers

✓ Accepted answer

Any variables held by a LocalScript is being ran BY the client, thus, a player leaving the game not only removes the variables, but also the VM so you shouldn't worry about any garbage leftover.

if a local script, probably not.

The local script will be destroyed anyways when they leave.

if on the server, probably yes.

Suppose you have a session table:

local session_data = { }

-- when they join...
session_data[player] = { } -- table of their data

-- when they leave...
save_data(player, session_data[player])

If you don't clear their index when they leave this could cause potential memory leak. You still have a reference to the player which is the key. You don't need to keep the data around when they leave anyways.

session_data[player] = nil

But don't worry about efficiencies or optimizations too much.

#1 rule of optimization: Don't do it. #2 rule of optimization: Don't do it yet.

2 comments

0

Right, I'm already cleaning playerdata from the server I was just curious if there was any reason to do it on the client. Just in case there was some potential for memory leaks or something I didn't know about

0

why did he unaccept your answer

This discussion is preserved as it was. New answers, comments, and votes are closed.