lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This code segment initializes a table with values 1 to 10000. It then
removes all the elements except the last.  Question: why has the
memory count not been reduced?

t = {}
for n = 1,10000 do
    table.insert(t,n)
end
collectgarbage("collect")
print("MEM:",collectgarbage("count"))
for n = 1, #t-1 do
    table.remove(t, 1)
end
collectgarbage("collect")
print("MEM:",collectgarbage("count"))
table.foreach(t,print)

prints:
MEM:	275.8583984375
MEM:	275.8583984375
1	10000

I've run this on both Linux and WinXP with the same results.

Thanks,
Bill