[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re: Help ! A problem with the memroy
- From: "Aurora" <bravefly@...>
- Date: Tue, 13 Apr 2010 10:00:29 +0800
Dear Sam,
"Possibly, it's because the last file created global vars, and the gc
doesn't know that they will never be used again. "
That's it. You are so bright.
The method you give is ok. But I need to do it in the C source code of lua, not in lua.
I want to know how could I delete all the objects and memory produced by the last lua file.
such as:
luaF_close(L, L->top);
free_reg_table(L, h);
free_global_table(L, h);
free_all_rootgc(L, h);
free_all_str(L, h);
------------------
Aurora
2010-04-13
-------------------------------------------------------------
From:Sam Roberts
Date:2010-04-13 09:46:15
To:Lua list
CC:
Subject:Re: Help ! A problem with the memroy
2010/4/12 bravefly <bravefly@gmail.com>:
> But GC can't collect all the memory used by last lua file.
Why not? You have to figure out why the memory isn't collected.
Possibly, it's because the last file created global vars, and the gc
doesn't know that they will never be used again, so keeps them around?
If that's the case, then try useing setfenv() to create a global env
for just the last file, then discard it after running the file.
Something like:
f,emsg = loadfile(filename)
if not f then
print(emsg)
else
local g = setmetatable({}, {__index=_G})
setfenv(f, g)
local ok,emsg = xpcall(f)
if not ok then
print(emsg)
end
g = nil
collectgarbage()
collectgarbage()
collectgarbage()
end
(typed from memory, YMMV)
Hao's suggestion to tune the gc to collect more often is a good one, too.
Sam