I just recently discovered weak tables. That brings up a question (see the title of the topic).
When does garbage collection happen in CC?
Started by LBPHacker, Jan 07 2014 10:18 AM
6 replies to this topic
#1
Posted 07 January 2014 - 10:18 AM
#2
Posted 07 January 2014 - 10:45 AM
Whenever it wants to/needs to. I've never noticed any GC issues. I don't know how well LuaJ supports weak tables.
#3
Posted 07 January 2014 - 10:52 AM
As CC uses LuaJ, which runs java 100%, it most likely behaves like the java GC - which is described here: ( http://www.oracle.co...gc01/index.html )
#4
Posted 07 January 2014 - 05:18 PM
Anyway. I managed to force a garbage collection cycle using this sneaky piece of code (CC 1.53 (yeah, I know, outdated version)):
function collectgarbage()
local a = setmetatable({{}}, {__mode = "v"})
while a[1] do
term.setCursorPos(term.getCursorPos())
-- Not doing anything in here breaks the top-level shell for some reason
end
end
collectgarbage()
print("gotcha")I'm not sure if that really forces a GC cycle, but it certainly prints "gotcha"
Edited by LBPHacker, 07 January 2014 - 05:18 PM.
#5
Posted 08 January 2014 - 06:42 AM
<p>Found this command in the lua documentation, too.
But it doesn't seem to work: lua-prompt says to
collectgarbage
nil
So there isn't that function from computercraft itself/p>
But it doesn't seem to work: lua-prompt says to
collectgarbage
nil
So there isn't that function from computercraft itself/p>
Edited by wieselkatze, 08 January 2014 - 06:45 AM.
#6
Posted 08 January 2014 - 09:28 AM
AFAIK it tosses all data that is not accessible via a handle/variable as soon as the variable is redefined
#7
Posted 08 January 2014 - 11:15 AM
Garbage collector manual calls were removed from cc due to safety and performance. The garbage collection is called as soon as an object is dereferenced (and in between when it expects a object to die, see aging process ). It can take some time if there are many object to collect but usually is instant.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











