The only time table.sort() should be causing "garbage memory" is if you are creating a new sort function every time you call it instead of re-using a single function.
Bad:
Code:
table.sort(my_table, function(a, b)
if a.name < b.name then
return true
else
return false
end
end)
Good:
Code:
local function MySortFunction(a, b)
if a.name < b.name then
return true
else
return false
end
end
table.sort(my_table, MySortFunction)