[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Iteration problems: Not a weak table issue
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 02 Dec 2004 13:57:27 -0200
> That exact code is called removekey in lgc.c in Lua 5.0.2.
Yes, but in 5.0 it was called only to remove dead keys from weak
tables. Now it is called to remove all unused keys from a table.
The problem is created by incremental collection (as expected).
Assume the following sequence of events:
- a[x] = nil
- a is traversed; because x has a nil value, it is not marked.
- a[x] = non-nil; because x is not a new key, there is no write barrier.
- x = nil; now the only reference to "x" is as a key, which was not
- x is collected, leaving a dangling reference in table a.
So, either x must be cleared from table a (so that a[x] = non-nil
triggers a write barrier) or the write barrier must be more complex
(bad for performance); or we find something better (try to put the
work on the `next' function?).