lua-users home
lua-l archive

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

Quoth dptr1988 <>, on 2011-02-03 18:13:45 -0800:
[paragraphs reflowed]
> That's basically what I did, but the C shared library still seems to
> be loaded in the memory and pmap still shows that it's there.
> "unrequire" successfully removes the Lua visible references to a C
> shared library, but it doesn't actually unload it from the
> memory. From what I can tell, ll_unloadlib() is only called when the
> userdata with the shared library handle is GC'ed ( which usually is
> when the Lua state is closed, since the userdata is in the registry )

The underlying problem is not as easy to solve generally as one might
think.  You cannot safely unload a C library until all ways of calling
any C functions in that library and all pointers to memory that might
be managed by that library are gone.  But lua_pushcfunction and kith
aren't normally called with any Lua handle to the C library, AFAIK, so
the GC can't directly see such references, and forcing the matter is
risking a segfault in the future if any other piece of code, say,
detected the library was loaded and stashed away a reference to one of
its functions behind a pile of closures.

Obviously there are cases where this is much more predictable, but it
makes sense that unloading C libraries is a dangerous thing that would
require poking around to do.

> Peter

   ---> Drake Wilson