Simply assign myTable = nil
is fine. You can test it like this, using the __gc
metamethod:
myTable = {}
for n=1,5 do
local item = {
name = "item"..n,
id = n,
}
setmetatable(item, {__gc = function (self) print("item " .. n .." collected") end})
myTable[n] = item
end
myTable = nil
collectgarbage()
Output:
item 5 collected
item 4 collected
item 3 collected
item 2 collected
item 1 collected
This means all the item
tables are collected by the garbage collector.