lua-users home
lua-l archive

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


On Jun 13, 2012, at 17:47, Peter Cawley <lua@corsix.org> wrote:

> On Wed, Jun 13, 2012 at 11:32 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>> So, if I looped with pairs(a), it would be there. __mode = 'k' and it
>> would not. Correct?
>
> If you looped with pairs(a), it would be there.
> If __mode=='k' and you looped with pairs(a), then it might be there or
> it might not, depending on how much work the garbage collector had
> done since you removed the other reference to the table.
>

I was thinking about that. So let's say you call collectgarbage()
prior to the loop. Then you loop through the elements, which for
pretend, are a bunch of callbacks.

One of the callbacks destroys an object, which in turn had a
callback() in the loop, which had not yet been called.

The only way to guard against this is to collectgarbage() in every
loop iteration.

So my next question is, how expensive is collectgarbage()?

--Andrew