lua-users home
lua-l archive

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


Antero Vipunen wrote:
Hello All,

I have a strange problem with GC.
I assigned __gc metamaethod for my objects to trace gcollection
and discovered that when i create luathreads using lua_newthread, run
some scripts in them and then call lua_setgctreshold(0), all my
objects become gc'ed except created in thread, that was created last.

Is it a bug or special feature?


I think your problem is that the threads themselves are getting collected, followed by the objects they created (if they're not referenced from somewhere else).

Remember that threads are regular lua values, and like tables they will be collected if they're not referenced anymore. On the C side, lua_newthread() returns the state, but it also pushes a thread object on the lua stack. You need to keep this value somewhere (like in the registry) if you don't want your thread to unexpectedly die...

So, unless I'm mistaken, this a bug of your code and a feature of lua ;-)

--
Julien Cugnière