|
Theoretical correct, but what code would do this? Define a variable, and then make it inaccessible by shadowing it. Common cases are to do this in inner blocks etc, different scoping, so after the shadowing scope ends the original is accessible again. If you don't use the '{ a_very_big_table }' any more, remove it.
> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Tim Hill
> Sent: zaterdag 24 augustus 2013 3:39
> To: Lua mailing list
> Cc: SLONIK.AZ@gmail.com
> Subject: Re: Lua strictlessness
>
>
> On Aug 23, 2013, at 5:59 PM, Tangent 128 <tangent128@gmail.com> wrote:
>
>
> function t()
> local a = {}
> w[1] = a
> cg() cg()
>
> local a = 2
> cg() cg()
> end
>
> This is really a side-effect of the non-optimizing Lua compiler; a quick
> look at luac output shows that each "a" gets a different stack slot, since
> the compiler does not perform scope analysis (hardly surprising).
>
> However, this does bring up an interesting issue for locals declared at
> the top-level scope in a long-lived script; as the earlier poster noted,
> these shadowed items will indeed live on until the script terminates so
> far as I can see.
>
> local a = { a_very_big_table }
> local a = 10
> -- The table is now inaccessible but reachable by the GC
>
> Of course, the quick answer is "don't do this", so I guess it might be
> worth noting somewhere in the Lua docs or wiki?
>
> --Tim
It's not a practical case. Though it might be a source of errors, I doubt it to be worth the extra compiler checks and balances for each local that is created.
Thijs