[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does not the finalizer been called at the end of the first or second for loop?
- From: Gé Weijers <ge@...>
- Date: Tue, 20 Oct 2020 07:22:09 -0700
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é