lua-users home
lua-l archive

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

* John Dunn:

> 1000 sockets will likely be created before any of the non-referenced
> userdatas are collected. I can solve this with require careful script
> coding ( having a sock:close() call that has to be called when you are
> done with the socket, calling collectgarbage(), etc ) but I'd like a
> solution that is more robust than that. It seems like a way to tag
> something to always be garbage collected as soon as there are no
> longer any references might work.

Unfortunately, there doesn't seem to be an efficient way to spot when
references go away immediately and still deal with cycles.  Even
ignoring the cycle problem, reference counting tends to have a higher
overhead than tracing collectors (at least for heaps of smaller

Another option would be to trigger a garbage collection when a
resource limit is exceeded.  But this only works for EMFILE (process
file descriptor limit exceeded), not for ENFILE (system limit
exceeded).  The latter might require triggering garbage collection in
*another* process, which isn't feasible.

So explicitly freeing non-memory resources is currently the way to go.
If you control your entire application environment, you can at least
avoid protected calls if you use finalizers and perform a full garbage
collection at the start of each exception handler.