[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Help ! A problem with the memroy
- From: Sam Roberts <vieuxtech@...>
- Date: Mon, 12 Apr 2010 18:45:48 -0700
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