lua-users home
lua-l archive

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




On Tue, May 2, 2023 at 12:18 AM Pierre Chapuis <lua@catwell.info> wrote:
x[1] is {} which, evaluated as a boolean, is true in Lua. The only false objects are `false` and `nil`, unlike other languages such as Python.


As 'x' has weak values the original author expected the garbage collector to dispose of the {} value eventually, but the Lua garbage collector was not running because the loop did not allocate any storage. Adding "local tmp = {}" to the body of the loop causes the loop to terminate eventually because x[1] will return nil.

The crucial point is that the Lua garbage collector is called by the routines that allocate storage.

--