lua-users home
lua-l archive

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


If you create a sequence with length 2^n, erase all the elements
except those with keys 1,2,4,8,16,...,2^n, and call collectgarbage(),
Lua does not release the memory.

n=20; t={}; for k=1,2^n do t[k]=k end
for k=1,#t do if math.log(k,2)%1 ~=0 then t[k]=nil end end
print("memory in use before 'collectgarbage()': "..(collectgarbage"count"))
collectgarbage()
print("memory in use after 'collectgarbage()': "..(collectgarbage"count"))

Output:

memory in use before 'collectgarbage()': 16409.73828125
memory in use after 'collectgarbage()': 16406.772460938

There's probably some subtlety I don't understand.