Search the Community
Showing results for tags 'locals'.
-
Hi, I was curious when the garbage collector would clean something like this: function testFunction () local testVariable = 100 local function firstFunctionInBlock () print("first function, testVariable: " .. testVariable ) testVariable = testVariable + 1 end local function secondFunctionInBlock () print("second function, testVariable: " .. testVariable) testVariable = testVariable + 1 end return function () firstFunctionInBlock() secondFunctionInBlock () end end function testFunction () -------------------------- -- function block -- -------------------------- end Executed with: local newCreatedFunction = testFunction() newCreatedFunction() newCreatedFunction() newCreatedFunction() -- print("--") -- local newCreatedFunction2 = testFunction() newCreatedFunction2() newCreatedFunction2() newCreatedFunction2() Results: first function, testVariable: 100 second function, testVariable: 101 first function, testVariable: 102 second function, testVariable: 103 first function, testVariable: 104 second function, testVariable: 105 -- first function, testVariable: 100 second function, testVariable: 101 first function, testVariable: 102 second function, testVariable: 103 first function, testVariable: 104 second function, testVariable: 105 I assume when I nil the function that is active in the block. newCreatedFunction = nil It will clear the first created function block by the garbage collector. newCreatedFunction2 = nil Same goes for clearing the second created function block. I did like to hear your opinion about this matter!