[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Memory leaks detected
- From: Wolfgang Oertl <wolfgang.oertl@...>
- Date: Wed, 5 Oct 2005 05:16:58 +0200
Hi,
as I mentioned before, the application I'm writing grows over
time, and I haven't been able to determine why -- until now. The
script shown below dumps all reachable memory and makes it fairly
easy to see what should have been deallocated.
Is there any memory that slips through? It considers keys,
values and metatables of tables.
BTW my main leak was lua-sqlite-0.3, because I didn't know about
(auto)closing statements, which is not mentioned in the
documentation.
Cheers,
Wolfgang
function show_mem(tbl, path, seen)
local show = function(k, s)
if type(k) == 'table' and not seen[k] then
seen[k] = true
table.insert(path, tostring(s))
show_mem(k, path, seen)
table.remove(path)
end
end
for k, v in pairs(tbl) do
table.insert(path, tostring(k))
print(table.concat(path, "."), v)
table.remove(path)
show(k, "KEY")
show(v, k)
show(getmetatable(tbl), "META")
end
end
-- Do this before exiting your program:
-- show_mem(_G, {}, {})