If I use an instance as key, for example:
PlayerOwnedBadges = {
[player] = {}
}
and that key is destroyed. Does the associated value clear?
If I use an instance as key, for example:
PlayerOwnedBadges = {
[player] = {}
}
and that key is destroyed. Does the associated value clear?
If the key is a player object and then that key(player) leaves the game the value will not clear on its own. The value will still exist in the table, because Lua tables do not automatically detect when an instance or object like a player is destroyed.
You would need to manually handle the cleanup by doing something like this:
game:GetService("Players").PlayerRemoving:Connect(function(player)
PlayerOwnedBadges[player] = nil
end)
No. You will need to remove the key in all circumstances. Luau does provide a method to automate this through the metamethod __mode
, where you can enable weak references in the table. This type of reference does not inhibit the garbage collector from cleaning up the memory associated with the instance if no additional references exist. Regardless, I would stick with the surefire conventional method of manual memory management
Thank you and ArcaneLux for explaining this : )
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.