Metatables page contains information inaccurate to Luau's current behavior

Issue Area: DevHub Content
Page URL: Metatables

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 {}
7 Likes

This topic looks similar to a topic that I made almost 2 years ago.

There should be a note that states that only strong references from Luau code prevent a roblox userdata object from being collected, instead of the current note.