lua-users home
lua-l archive

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


On Mon, Sep 26, 2011 at 9:06 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> local f = open_connection()
> finalize(function(e)
>   f:close()
> end)

Any feelings/opinions about finalizers? My feeling is that it could be
done fairly efficiently, although of course the devil is in the
details:  the guiding principle is "don't pay for what you don't use".

This can already be done with pcall all over the place, but it's messy
(and inefficient to create all those closures).

What it does provide is support for RAII and thus guarantees that
resources will be properly closed under all circumstances. For
instance, if you allocated a big temporary object then you do not have
to wait for the next GC cycle to have its memory reclaimed.

It's not the only finalization proposal, see

http://lua-users.org/lists/lua-l/2008-02/msg00243.html

steve d.