[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: newproxy()
- From: Florian Weimer <fw@...>
- Date: Mon, 23 Nov 2009 21:33:03 +0100
* Roberto Ierusalimschy:
>> It might be better if there was some sort of __gcqueue metatable slot
>> which referred to an array. When the object becomes unreachable, it
>> is added to the __gcqueue array. Lua functions which interact with
>> these objects would process the queue. This way, the side effect
>> would occur at well-defined points in the program.
> We thought about that. (Alexandra Barros, who did the first
> implementation of ephemeron tables, also did a prototype implementation
> of this feature.) One problem is memory allocation. What the collector
> should do if there is a memory allocation error when resizing __gcqueue?
Can't you skip queuing the weakly-referenced object in that case,
marking it reachable instead? This does not guarantee forward
progress, but I suppose you can't do that anyway when memory is tight.
Java solves this by allocating enough pointer fields when the weak
reference is created, so that the queue data structure can use that
later without further memory allocations. This is probably not
suitable for Lua because you don't want the weak table machinery on
the ordinary table lookup path.