Issue Area: DevHub Content
Page URL: Metatables | Roblox Creator Documentation
The current page outlines a number of outdated metamethods, namely, __mode
DOES dispose of Roblox instances and script connections now.
The scripts used to test this
Instances:
local Storage = setmetatable({}, {__mode = "k"})
for i = 1, 100 do
local part = Instance.new("Part", workspace)
Storage[part] = true
end
print("Storage directly after creation: ", Storage) -- Prints a table with 100 elements
for part in pairs(Storage) do
part.Parent = nil
end
task.wait(1)
print("Storage 1 second after parenting all parts to nil: ", Storage) -- Prints {}
Connections:
local Storage = setmetatable({}, {__mode = "k"})
for i = 1, 100 do
local part = Instance.new("Part", workspace)
Storage[part.Touched:Connect(function() end)] = part
end
print("Storage directly after creation: ", Storage) -- Prints a table with 100 elements
for con, part in pairs(Storage) do
part.Parent = nil
end
task.wait(1)
print("Storage 1 second after parenting all parts to nil: ", Storage) -- Prints {}