#Will function locals cause a memory leak?
1 messages · Page 1 of 1 (latest)
the word "local" in lua defines a variable as contained to a "scope"
so it essentially streamlines cleaning up variables for you once the scope is no longer relevant to execution
to clarify
Essentially when i run the function again it just changes the variables of the locals
what about coroutines? i'm using coroutines to run multiple npc, when i use the function i wrap a coroutine with a while loop that constantly changes the path of the npc
Since there would be multiple loops going on, what would be the case here for when the NPC dies? since the loop is still going
x = 5 -- this is a variable in the global scope
local b = 5 -- this is also a variable in the global scope, having local changes nothing
function bitch()
local c = 6 -- this is contained to the "bitch" scope
end
-- c no longer exists
print(c)
nil
yeah, variables can't be used outside the functions i just wasn't sure if they take up memory in coroutines after they're dead