[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 5.1 collectgarbage: test case
- From: "Adam D. Moss" <adam@...>
- Date: Sun, 12 Mar 2006 09:36:27 +0000
Michael Broughton wrote:
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.
Not... entirely... correct on either count!
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
t.foo= "bar" -- <---- LOOK! MAGIC!
collectgarbage("collect")
print("MEM:",collectgarbage("count"))
table.foreach(t,print)
prints:
MEM: 210.0732421875
MEM: 18.1123046875
1 10000
foo bar
The (well-discussed, but perhaps not documented, as an
implementation detail) reason is that Lua only considers
shrinking a table's allocation on a non-nil new-index
write. (Empirically only a non-array non-nil new-index
write, at that.)
Cheers,
--Adam