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

[Solved]Datastore2: How does it handle garbage collection?

I've just set up a datastore using Datastore2 and started thinking about garbage collection. I thought "What happens if a server has been up for a LONG time? Wouldn't the game remember each in-game table for each individual player that has ever joined that specific server (assuming the server never goes down)?"

For example, the following code will retrieve the player's data (or set the default values of DefaultTable) and place the table inside playerData when the player joins the game:

local playerData = DataStore2(Key,plr):GetTable(DefaultTable())

Will this retain everyone's playerData (on that server) even after they leave?

Throughout the code I change values and "save" it to Datastore2. What happens when that player leaves? Is there a tether to that specific player's playerData that automatically sets it up for garbage collection as soon as the player leaves?

I apologize if this is something that isn't related to Datastore2, I just wanted to know if this is something I should take care of manually. Thank you.

1 answer

Just reviewing some of my old questions.

I answered this a while ago, but never officially gave an answer on here. The contents of the PlayerAdded function is garbage collected upon the player leaving the game. The game will keep any function for the individual player separated (i.e. There are actually multiple copies of remote events given to each player) from other players and will destroy the contents when the player leaves. If you're still worried, then you can set the variable/table to nil in PlayerRemoved to ensure the memory is cleared.

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