lua-users home
lua-l archive

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




On Tue, May 12, 2020 at 4:33 PM Andrea <andrea.l.vitali@gmail.com> wrote:
The automatic garbage collection in Lua, Java, C# etc. does not require you to do any of that, but it has a lot more overhead and does not free memory instantly, which is why the "<close>" facility was added in Lua 5.4.0.

let me double check to be sure I understand correctly: could one use <close> on tables and exploit this to free tables as soon as possible without waiting for the garbage collector to kick in?


No, the Lua runtime can't "prove" that there is no other reference to the same table, so it has to go through the regular process of marking all reachable objects. The __close metamethod is useful for releasing resources like files, window handles, etc. as soon as a local variable that references the object goes out of scope.

-- 

_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org