lua-users home
lua-l archive

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

On Friday 12 August 2005 14:08, Roberto Ierusalimschy wrote:
> I still think that we can do that with finalizers. As long as each
> object has a proper finalizer (i.e., a __gc metamethod), all we have to
> do in case of errors is to call collectgarbage() to finalize what was
> left.

I'd just like to point out that the various Java people we have here will, if 
you mention finalisers to them, start frothing at the mouth and using phrases 
like 'utterly brain-damaged', 'my god, what were they thinking', 'spawn of 
satan' and in some circumstances 'eeeeeeeaaaaaagh'.

Just think about these:

    local oo
      local o = createobject()
        oo = o
    end -- o becomes unreachable here
    -- What's oo set to now?
  end -- oo becomes unreachable here
  -- How many times did the finaliser get called?

      call_function_that_might_yield() -- what happens here?

Of course, Java makes life much harder for itself because of the vast plethora 
of different types of soft reference (there are *six* reachability states). 
Not pleasant.

Lua gets away with __gc because it has very restricted functionality; 
finalisers can only be written in C, the finalised objects can't be 
resurrected, the finalisers can't block, etc. IMO, this is a Very Good Thing.

+- David Given --McQ-+ 
|    | Quidquid latine dictum sit, altum viditur.
| ( | 
+- --+ 

Attachment: pgpOXOiSmN183.pgp
Description: PGP signature