Ive made a module recently that is required by all clients at the same time locally. It uses metatables for showing local character visuals on all characters.
Here is a version with just the important parts:
local dynamicJoints = {}
dynamicJoints.__index = dynamicJoints
function dynamicJoints.start(player)
print("started for player "..player.Name)
local connectionTable = {}
local function update(dt)
print("hello")
-- do stuff here
end
connectionTable.reset = game.ReplicatedStorage.Events.ResetDynamic.OnClientEvent:Connect(function(otherPlayer)
-- reset stuff here
end)
connectionTable.update = game["Run Service"].RenderStepped:Connect(update)
return setmetatable({
connections = connectionTable
}, dynamicJoints)
end
function dynamicJoints:stop()
print("stopped")
for _, connection in pairs(self.connections) do
if connection and connection.Connected then
connection:Disconnect()
end
end
setmetatable(dynamicJoints, nil)
end
return dynamicJoints
If I called :stop()
on this module and removed all variables referencing the metatable, would all the memory from the .start()
function get removed? Or will there be some memory left over? Ive redone my code multiple times and I dont want to do it again, which is why Im asking here