JeViCo Posted September 18, 2018 Share Posted September 18, 2018 Hello everyone. My question is in title - what does it exactly do? Does it clear global/local variables? Link to comment
Gordon_G Posted September 18, 2018 Share Posted September 18, 2018 Could you link what you are talking about ? Link to comment
JeViCo Posted September 19, 2018 Author Share Posted September 19, 2018 15 hours ago, Gordon_G said: Could you link what you are talking about ? i found this page and i think it can be useful. But i don't know what does it exactly clear/remove and when should i use it Link to comment
Gordon_G Posted September 19, 2018 Share Posted September 19, 2018 You're right, that's now interesting me too Link to comment
Moderators IIYAMA Posted September 20, 2018 Moderators Share Posted September 20, 2018 (edited) The collectgarbage cleans objects. The object you are probably familiar with is the table(a powerful hybrid between an object and an array if you know JavaScript). variable = {} When you create a table, it is not just creating it and save it in a variable. < This is actually incorrect. This is incorrect because you are not saving the table inside of a variable. A table is a THING, unlike the values 72675467 or "random string". THINGS are of course saved inside of the memory just like variables, but they exist not at the same place. Which means that what is actually is saved inside of a variable is a reference TO that TABLE. The benefit of a reference instead of just a value: local a = {1} local b = a b[2] = 10000 local c = a c[3] = "IIYAMA" iprint(a) -- {1, 10000, "IIYAMA"} -- magic! a = nil iprint(a) -- nil iprint(b) -- {1, 10000, "IIYAMA"} iprint(c) -- {1, 10000, "IIYAMA"} -- magic! b[4] = "this is more trash" b = nil iprint(a) -- nil iprint(b) -- nil iprint(c) -- {1, 10000, "IIYAMA", "this is more trash" } -- magic! c = nil iprint(a) -- nil iprint(b) -- nil iprint(c) -- nil As it isn't always known when all references are destroyed(which means the table can't be accessed any more), the garbagecollector will clean it after a while. (which happens in cycles) Do not use that function, if this is still hard to understand. This LUA function kills performance if not used correctly. = (The collector is forced to make a full cycle) So better not use it at all, as LUA can do a fine job doing it itself. Edited September 20, 2018 by IIYAMA 1 Link to comment
Gordon_G Posted September 20, 2018 Share Posted September 20, 2018 Thanks for your time 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now