lua-users home
lua-l archive

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




2014-11-18 1:14 GMT-08:00 Anton Titov <anton@titov.net>:
On 18.11.2014 06:47, arioch82 wrote:
>From what i understand if the coroutine is freed then all local variables
inside that function should be garbage collected, at that point the userdata
shouldn't have any references anymore and should be collected too but for
some reason this is not happening.

Every running function (and all the functions that called it) are referenced from the Lua stack and would not be collected even if there are no other references to them. This is a good thing that prevents crashes ;)

Corotines are actually functions called in separate Lua (sub-)states with a corotine library doing some scheduling. Therefore even yielded corotine is "running function" for the purposes in the first paragraph.

Your solution is to replace "while true do" with some more meaningful condition and call the corotine one more time when destroying to let it exit.

Best,
Anton


I doubt that a yielding coroutine is considered as a "running function". A yielding coroutine should logically be a "returned function" which could be picked up from the point it has yielded as a semi-continuation. It can be resumed, but from the point of view of GC, it is a returned function until it is resumed again.

Therefore, if a yielding coroutine lose all references pointing to it, it can never be resumed again and therefore should be GC-claimable.

Is my understanding above correct or not?

Thank you,
Dong