lua-users home
lua-l archive

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


I'm using Lua-5.3.0.

I integrated Lua in a C software. I created objects for mapping my own
C structs. Some object uses a lot of resources like memory and file

I built this design hoping that the Lua GC clean release my object when
it is no longer used by the Lua code. Of course, I use the special
function '__gc' for cleaning my own resources.

I run some Lua function in the same time, so I use coroutine.

This system run perfectly while I do not encounter errors.

When a function launched in a coroutine is terminated, I start the gc
and I see my resources freed. It is the expected behavior. I use as
parameter of the lua_gc function the "lua_State" returned by the
function lua_newthread() function. previously I remove the last
reference of my coroutine/thread in the main Lua stack. 

When the function is not terminated because it yield, or when the
function is terminated with an error, the lua_gc() doesn't release my
resources. I must run the lua_gc with the main stack as parameter.

It is the normal behaviour ? Do you have some tips for avoiding to call
the lua_gc function with the main thread when a error occurs ?

NOTE: it is mandatory to force the GC after the execution of some
Lua code because the allocated resources can be heavy and must be freed

Thank you,