This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Pharap's profile picture

Question about memory usage

Started by Pharap, 09 December 2012 - 11:26 AM
Pharap #1
Posted 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.
MemoryLeak21 #2
Posted 09 December 2012 - 02:11 PM
If you do something like this:



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.
snoble2022 #3
Posted 10 December 2012 - 09:52 AM
Lua automatically handels memory, so you shouldn't have to worry about it.
MemoryLeak21 #4
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.
Cloudy #5
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.
MemoryLeak21 #6
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.)
PixelToast #7
Posted 10 December 2012 - 01:56 PM
the garbage collector deletes unreferenced objects to free up memory .-. not sure exactly how it works though
If I said that that happens, don't you think I think it happens?
(HINT: That's what I meant.)
correct, but id rather not talk about psychology .-.

also, avoid stacks of quotes by -snip- ing
especially when the person you are quoting is right above you
MemoryLeak21 #8
Posted 10 December 2012 - 03:59 PM
Yes, sir.

(I was gonna quote you, but then I analyzed my logic.)
PixelToast #9
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
Cranium #10
Posted 10 December 2012 - 05:46 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
I see someone is playing around with the various BBCodes available…..
Cloudy #11
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.
snoble2022 #12
Posted 31 December 2012 - 09:23 AM
Wow, Cloudy, don't you think that was a bit overboard?
Cloudy #13
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.