What about
for i = #spaceMen,1,-1 do
spaceMen[i]=nil
end
which runs about 25% faster in this testcode
local i,n,t,s
local tRemove=table.remove
collectgarbage("collect")
collectgarbage("stop")
print(collectgarbage("count"))
s=system.getTimer()
for n=1, 1000 do
t={}
for i=1,10000 do
t[i]={i}
end
for i = #t,1,-1 do
-- table.remove(t, i);
-- tRemove(t, i);
t[i]=nil
end
end
print("time: "..(system.getTimer()-s))
print(collectgarbage("count"))
collectgarbage("restart")
collectgarbage("collect")
print(collectgarbage("count"))
I tested some garbage collector related stuff with that code earlier too. Kinda useless though besides of getting better results for direct comparison of implementations.
But for the OP example the t={} … or t=nil would be of course the best solution
[import]uid: 6928 topic_id: 1098 reply_id: 3238[/import]