lua-users home
lua-l archive

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


> > I already explained the reason. If you think it is not a good one, too
> > bad; it is the only one. Once more: The call can fail due to lack of
> > resources, but there is a good chance that the error itself will free
> > those resources (e.g., stack space); so, the next call can succeed where
> > the previous one failed. The option would be not to repeat the call, and
> > therefore not to close whatever should be closed.
> 
> I understood the above. But I do not understand the details, and also
> the bigger picture.
> When you say 'due to lack of resources' - do you mean a scenario like
> failure in malloc()?

As hinted in the message ("stack space"), the paradigmatic scenario
is stack overflow.  When Lua tries to call the close method, or when
the close method tries to call an auxiliar function, there is a stack
overflow, that is, the maximum number of calls allowed by Lua (or the
maximum number of stack slots in use) is exceeded. In this case, the
error will make Lua jumps out of at least one function, opening space
for the close method.

But also we do not have such a grim view of memory allocation failures.
Often the program is doing one particular task that demands lots of
memory. Once that task is aborted, memory is back to normal levels and
the program can continue doing other tasks. (As an analogy, you should
not need to restart your computer if a process is killed by lack of
memory.)

-- Roberto