View Single Post
04-17-14, 06:05 AM   #12
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by Sharparam View Post
This is not correct. By doing t.func = nil you are just making t.func no longer reference that function. Any other references to the function are still valid.

You are assigning nil to t.func, not assigning nil to the actual function stored in memory. Both t.func and frame.func are just pointers to that function.

(I could be wrong in any of my statements, someone please correct me in that case.)

Using a table as an example where you can see the change in both references (because tables are reference types in Lua):

lua Code:
  1. local t = { foo = "bar" }
  2. local a = { t = t }
  3. local b = { t = t }
  4. print(a.t.foo) -- prints "bar"
  5. print(b.t.foo) -- prints "bar"
  6. b.t.foo = "baz"
  7. print(a.t.foo) -- prints "baz"
Ah okay.

Just to confirm my understanding. When I write...

t.func = nil;

... does lua check to see if the function is referenced by anything else. If it is, it keeps it, if not, it gets wiped from memory by the garbage collector?
__________________
__________________
  Reply With Quote