Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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?

0
But why did you unaccept my answer over a shorter less explaining programmerHere 371 — 4y
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 aquathorn321 858 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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.

Ad
Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

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.

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 aquathorn321 858 — 4y
0
why did he unaccept your answer speedyfox66 237 — 4y

Answer this question