lua-users home
lua-l archive

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


This is normal. Lua grows it memory pool as needed, it does not reduce it. also, collectgarbage("count") reports the current size of Lua's memory pool, not how much of the pool is being used.



William Trenker wrote:
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