[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Basic question on weak keys
- From: Andrew Starks <andrew.starks@...>
- Date: Wed, 13 Jun 2012 17:54:31 -0500
On Jun 13, 2012, at 17:47, Peter Cawley <firstname.lastname@example.org> wrote:
> On Wed, Jun 13, 2012 at 11:32 PM, Andrew Starks <email@example.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
So my next question is, how expensive is collectgarbage()?