Re: __gc support for tables

  • From: Mike Pall <mike-1409@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 3 Sep 2014 19:53:03 +0200

Roman Tsisyk wrote:
> Do you have any plans to support `__gc' metamethod for tables in
> LuaJIT 2.0.x / 2.1.x?

Scheduled for the new GC, which is not part of 2.x.

In general, finalizers are for cleanup of resources that are NOT
memory resources. A plain table only uses memory resources, but it
may reference objects that do (userdata, cdata). Finalizers should
be attached to these objects, not to the containing table.

An assumed need to attach a finalizer to a table is often misguided
and the overall data structure design should be reviewed. There are
very few valid reasons to do this, which is why there has been no
pressing need to implement finalizers for plain Lua tables. Like
all finalizers, it has it's hidden costs.

--Mike

Other related posts: