Hello, and a Happy New Year!
I have this code, which creates a table for each player, referencing a server-sided object and whether or not the player has completed said task (that part isn’t really relevant).
--[[
Creates references to the created task
object and it's completion status.
@returns N/A
--]]
function TaskService:CreatePlayerTasks( player )
player = player.instance or player
--? This player already has tasks created.
if (self.players[player]) then
return
end
self.players[player] = {}
for _, task in next, self.tasks.main do
table.insert(self.players[player], {
task = task;
hasCompletedTask = false;
})
end
self.progress.active += #self.players[player]
end
--[[
Clears references to the task objects
so they can be GC'd properly later.
@returns N/A
--]]
function TaskService:ClearPlayerTasks( player )
--? This player has no tasks.
if (not self.players[player]) then
return
end
self.progress.active -= #self.players[player]
self.players[player] = {}
end
In the :ClearPlayerTasks()
method, I’m setting self.players[player]
to nil. Will that allow the objects created to be garbage collected later to avoid a memory leak, or do I first have to loop through the table and then set task
to nil first?
And how would I properly destroy an object using a :Destroy()
method in it?