Does this create a memory leak?

From my understanding, it wouldn’t contain a reference to the player Instance since you’re storing a number which is their UserId. Regardless, you can remove their UserId from the table upon leaving:

local myDictionary = {}

Players.PlayerAdded:Connect(function(Player)
    local userId = Player.UserId
    myDictionary[userId] = true
end)

Players.PlayerRemoving:Connect(function(Player)
    local userId = Player.UserId
    
    if myDictionary[userId] then
        myDictionary[userId] = nil
    end
end)

More info about memory leaks as well as Weak & Strong References (which pertain closer to the scope of this topic) can be found on the following topic:

1 Like