lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Oct 19, 2020 at 1:33 AM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> --Question:
> --                Why does not the finalizer been called here after
> "list = v" has been invoked?
> --                For the former variable "list" is still referenced
> by "k,v in pairs(list)"?
> --                If the guess aforementioned is right, why does not

you call 'collectgarbage' in the for loop. "pairs" returns the
function "next", its parameter (list), and nil. The for loop will keep
the 'list' value on the stack until you exit the loop. So "list = v"
does not make the old value of 'list' unreachable, and collectgarbage
cannot collect the value yet. All of this is easy to figure out from
the definition of "pairs" and the description of the for loop in the
Lua manual.

Gé




-- 
Gé