#Will function locals cause a memory leak?

1 messages · Page 1 of 1 (latest)

worthy patrol
#

I'm trying to make a spawn functionf or NPCs, and as you can imagine i have to make locals for their animators and other things.

Do i have to clear out all of the locals once the NPC dies? should i put all of them under a table so i can easily clear them?

lime helm
#

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

worthy patrol
#

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

lime helm
#
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

worthy patrol
#

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

lime helm
#

they definitely do not

#

coroutines once dead are permanently annihilated