Hi. Making a Capture The Flag game and I’m using OOP for a Flag object. I want to instantiate a new Flag object every round and destroy it at the end of the round.
Currently, I have a :Destroy()
method in my Flag class which uses a Maid object to destroy the flag’s model and also disconnects any connections in my flag object:
function Flag:Destroy()
self._maid:GiveTask(self.model)
self._maid:Destroy() -- Cleans up all connections + destroys self.model
end
If I have a setup on a server script like this:
local Flag = Flag.new(...)
Flag:Destroy()
Flag = nil
Will my flag object get garbage collected? I’m just concerned a bit about memory (which I’m 100% not very knowledegable about) since if it hangs around in memory then (as I’m instantiating a new Flag object every round) I assume my used Flag objects will take up a considerable amount of my server’s memory over time.
I’m also unsure on how to actually check whether it has been garbage collected or not as I don’t quite understand how to use Studio’s tools for checking memory usage.
My other solution is to make it so I can reuse the same Flag object every round which may probably be better but I’d rather preserve my current method out of convenience.