758 posts
Location
Budapest, Hungary
Posted 07 January 2014 - 10:18 AM
I just recently discovered weak tables. That brings up a question (see the title of the topic).
8543 posts
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.
28 posts
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.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html )
758 posts
Location
Budapest, Hungary
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 on 07 January 2014 - 04:18 PM
227 posts
Location
Germany
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>
Edited on 08 January 2014 - 05:45 AM
1548 posts
Location
That dark shadow under your bed...
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
28 posts
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.