Do local variables in lua occupy memory after end of scope?

54 Views Asked by At

--script.lua local x = 0

--main.lua dofile("script.lua")

Now we are out of script.lua scope, so we can't directly access x variable. But it still exists and its definition occupies memory even if x == nil. How can I delete x completely? Or How can I load thousands of scripts to do some stuff and release these scripts one by one completely? I dont need their locals in my memory anymore

The only thing that worked is BAD EVIL globals. If i use global x = 0, then x = nil do what i want, but every pro lua user keep saying that globals are bad.

2

There are 2 best solutions below

1
Luke100000 On BEST ANSWER
1
Tanako Tybe On

Okay, I found this in "The implementation of Lua": --Once a closed upvalue is no longer referred by any closure, it is eventually garbage collected-- Click noice!