lua-users home
lua-l archive

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

On Wed, Mar 15, 2006 at 02:15:09PM -0300, Luiz Henrique de Figueiredo wrote:
> > One apparently missing feature in Lua's user-supplied allocator support 
> > is a way for the allocator to be notified when it's already needed, so 
> > it can free associated resources.
> The standard way to free any host resources at Lua close time is to add
> an entry in the registry. This entry sets a userdata with the appropiate
> gc method, which will only be called when the registry is freed, ie, when
> Lua closes. (If your application replaces the registry, you'll have to
> recreate the entry there.)

Unfortunately this scheme does not work in this case. The __gc
metamethods are called long before all Lua memory has been released.

You can use another trick: the main lua_State L is the first thing to
be allocated and the last to be deallocated. So, your allocator can
store somewhere the result of its first allocation; when it is asked
to free that first block, it knows everything is finished.

-- Roberto