[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua 5.1: debug.sethook() may cause leaks
- From: Arseny Vakhrushev <arseny.vakhrushev@...>
- Date: Mon, 16 Jan 2012 19:52:00 +0400
Hello, List!
Please consider the following code:
------- test.lua ------
local function printState()
collectgarbage 'collect'
print(collectgarbage 'count')
end
printState()
do
local t = {}
for i = 1, 10000 do
local co = coroutine.create(function () end)
debug.sethook(co, function () end, 'l')
table.insert(t, co)
end
end
printState()
--------------------
Output:
$ lua test.lua
27.6533203125
1058.3408203125
$ luajit-2.0.0-beta9 test.lua
23.71875
24.5673828125
After a little investigation into what may occupy memory, I found that debug.sethook() leaves some internal data in the registry despite the corresponding coroutines have been collected. LuaJIT manages to free them as it probably should.
// Seny