[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: bug in 5.0
- From: Chromix <Chromix@...>
- Date: Wed, 04 Jan 2006 18:58:28 +0100
As far as we checked, this bug is not present in Lua 5.1 beta.
I've created another variant of my demonstration script for 5.1,
which uses 5 empty tables that occupy about 60MB of RAM.
If it is not a bug, it is at least unexpected behaviour.
I've used http://www.lua.org/work/lua-5.1-beta.tar.gz
for testing the script on linux.
-------<snip>-------
-- Weak values & garbage collection problem, Version for Lua 5.1 beta
--[=[
Output on linux:
Lua 5.1 (beta)
Loop 1
44603 --> 12602
Loop 2
57185 --> 25185
Loop 3
69768 --> 37768
Loop 4
82351 --> 50351
Loop 5
94934 --> 62934
]=]
print( _VERSION );
local t = {};
for loop = 1, 5 do
print( "Loop", loop );
-- Create a new local table with weak values.
local tTest = setmetatable( {}, { __mode = "v" } );
-- Fill the table, and make sure the GC won't get triggered
-- while it is being filled.
collectgarbage( "stop" );
for i = 1, 1000000 do
tTest[i] = {};
end
-- The table will contain 1000000 entries now.
local count = 0;
table.foreach( tTest, function() count = count + 1; end );
assert( count == 1000000 );
-- Run the GC. All values are weak and unreferenced...
local usage = math.floor( collectgarbage("count") );
collectgarbage();
-- ...so the table is empty now.
assert( not next( tTest ) );
print( usage, "-->", math.floor( collectgarbage("count") ) );
-- Store the empty table. This should not consume a lot of RAM
t[loop] = tTest;
end
-------</snip>------