I had noticed this issue when working on the last test-case. Almost forgot about it. Attached is a simplified test-case that show how a closure's upvalue is not collected (maybe the closure is also not collected, not sure). The standard Lua VM will free the memory used by the upvalue, so I am sure that the references to the memory have been released and it should be collectable. Disabling the JIT allows the memory to be collected, so I guess the JIT compiled code is keeping a reference to the table and keeping it from being collected. -- Robert G. Jakabosky
local lim = tonumber(arg[1]) or 1000 local function mem() return math.floor(collectgarbage"count") end local function run_test() local upval = {} local function test_closure() -- fill table at upvalue 'a' with lots of memory for i = 1, lim do local t = {} for x = 1, lim do t[x] = x end upval[i] = t end end test_closure() print('Lua mem Kb=', mem()) print("Free table.") test_closure = nil -- release closure upval = nil -- release table. collectgarbage"collect" collectgarbage"collect" collectgarbage"collect" collectgarbage"collect" print('Lua mem Kb=', mem()) end run_test()