lua-users home
lua-l archive

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

> Ideally we'd get a construct that allows us to elegantly request immediate
> destruction of particular resources. Emergency collection doesn't make that
> construct less likely to emerge unless the Lua authors would be contented by
> emergency collection. That's not my impression but maybe I'm wrong about
> their motivations. In any event, let's not let the perfect be the enemy of
> the better.

Even without any new construct, the idea of "emergency collections"
is not intended to be the basic method of resource release. We still
believe that programmers should call explicit 'close' methods after
using a resource.  Only in exceptional circunstances (mostly when
exceptions occurr) the regular 'close' method would not be called.
Even then, regular garbage collection would deal with most of these
leftovers. I would expect that in a well-written program, "emergency
collection" would be really rare, but we have no data on this.

Moreover, it is worth keeping in mind that we are talking about
operations that can still fail honestly (e.g., your program really may
have too many open files, or worse, the system has too many open files,
errno ENFILE).  If the program can sustain such failures, it probably
can sustain a full GC cycle---with less damage. It is also worth keeping
in mind that real emergency GCs can happen at every single allocation
(e.g., in an assignment to a table field), so it should not be such a
big deal.

Finalization of iterators is a different matter. Unlike regular stuff,
it seems that programs can skip their finalizers (by breaking the loop)
in non-exceptional circunstances, and there is not much programmers can
do about that currently. As pointed out, none of the proposals being
discussed would solve that. Maybe the proposal just made by John
solves that.

-- Roberto