[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: garbage collection and setfenv
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Tue, 18 Mar 2008 20:24:25 -0600
Running the following in the Lua interpretter:
function tryThis()
myVar = newproxy()
print(myVar)
local mt = getmetatable(myVar) or {}
debug.setmetatable(myVar, mt);
mt.__gc = function()
print("!!! cleanup")
end
end
function yup()
setfenv(tryThis, setmetatable({}, { __index = _G }))
tryThis()
setfenv(tryThis, {})
collectgarbage()
end
yup();
The following is output:
batrick@waterdeep:~$ lua test.lua
userdata: 0x806f9ec
!!! cleanup
I believe your problem is that you are expecting the environment to be
collected when a local variable has a reference to it =)
Cheers,
--
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant