I would assume yes, but I want to be absolutely sure.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Question about memory usage
Started by Pharap, 09 December 2012 - 11:26 AMPosted 09 December 2012 - 12:26 PM
If I make a table with several functions in it, (eg tab.somefunc = function() print(5) end) and then nil the table (eg tab = nil) I assume that providing there is no external link to those functions (eg local f = tab.somefunc) the garbage collector will automatically nil them so that the function that was referenced by tab.somefunc no longer exists?
I would assume yes, but I want to be absolutely sure.
I would assume yes, but I want to be absolutely sure.
Posted 09 December 2012 - 02:11 PM
If you do something like this:
Then the function somefunc() will still exist, but tab will be nil. But if you remove the somefunc() declaration statement:
Then the function in somefunc will not exist. Is that your question? Or do you mean to ask if any functions equal to tab.somefunc will be erased as well? In that case, no. They stay the same.
local tab = {
somefunc = function() print(5) end
}
somefunc() = tab.somefunc
tab = nil
Then the function somefunc() will still exist, but tab will be nil. But if you remove the somefunc() declaration statement:
local tab = {
somefunc = function() print(5) end
}
tab = nil
Then the function in somefunc will not exist. Is that your question? Or do you mean to ask if any functions equal to tab.somefunc will be erased as well? In that case, no. They stay the same.
Posted 10 December 2012 - 09:52 AM
Lua automatically handels memory, so you shouldn't have to worry about it.
Posted 10 December 2012 - 11:16 AM
Lua automatically handels memory, so you shouldn't have to worry about it.
Unless you overload the stack by having functions call themselves.
Posted 10 December 2012 - 12:42 PM
Lua automatically handels memory, so you shouldn't have to worry about it.
Unless you overload the stack by having functions call themselves.
Even then you'll get to a limit - and it will error, which should move the functions out of scope and mark the variables for garbage collection.
Posted 10 December 2012 - 01:09 PM
Lua automatically handels memory, so you shouldn't have to worry about it.
Unless you overload the stack by having functions call themselves.
Even then you'll get to a limit - and it will error, which should move the functions out of scope and mark the variables for garbage collection.
If I said that that happens, don't you think I think it happens?
(HINT: That's what I meant.)
Posted 10 December 2012 - 01:56 PM
the garbage collector deletes unreferenced objects to free up memory .-. not sure exactly how it works though
also, avoid stacks of quotes by -snip- ing
especially when the person you are quoting is right above you
correct, but id rather not talk about psychology .-.If I said that that happens, don't you think I think it happens?
(HINT: That's what I meant.)
also, avoid stacks of quotes by -snip- ing
especially when the person you are quoting is right above you
Posted 10 December 2012 - 03:59 PM
Yes, sir.
(I was gonna quote you, but then I analyzed my logic.)
(I was gonna quote you, but then I analyzed my logic.)
Posted 10 December 2012 - 05:43 PM
but [acronym='memoryleak']captain[/acronym], i do not believe you have sufficient rank to promote me to [acronym='sir']admiral[/acronym] http://puu.sh/1zgql
anyway, here is a link to how the garbage collector works .-. http://lua-users.org...rbageCollection
memory management is always confusing
anyway, here is a link to how the garbage collector works .-. http://lua-users.org...rbageCollection
memory management is always confusing
Posted 10 December 2012 - 05:46 PM
I see someone is playing around with the various BBCodes available…..but [acronym='memoryleak']captain[/acronym], i do not believe you have sufficient rank to promote me to [acronym='sir']admiral[/acronym] http://puu.sh/1zgql
anyway, here is a link to how the garbage collector works .-. http://lua-users.org...rbageCollection
memory management is always confusing
Posted 10 December 2012 - 10:31 PM
If I said that that happens, don't you think I think it happens?
(HINT: That's what I meant.)
You weren't clear on that point. No need to be an asshole about it.
Posted 31 December 2012 - 09:23 AM
Wow, Cloudy, don't you think that was a bit overboard?
Posted 31 December 2012 - 09:43 AM
No, I don't. I also don't think it is overboard that I'm closing this thread for an unneccesary bump which adds nothing.