lua-users home
lua-l archive

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


It was thus said that the Great Andrew Gierth once stated:
> >>>>> "Sean" == Sean Conner <sean@conman.org> writes:
> 
>  >>>> An object reference may be abandoned as soon as the program gets
>  >>>> to the point where it will no longer need the object for its
>  >>>> normal execution (i.e. ignoring the effects of weak references and
>  >>>> finalizers). The finalizer can run any time after that (1ns or 1
>  >>>> year later).
> 
>  Roberto> +1.
>  
>  >> So if one needs to prevent an object's removal from a weak table
>  >> during the execution of a block of code, how should it be done, if
>  >> simply assigning the value to a local isn't enough?
> 
>  Sean> Assigning it to a local is enough to keep it from being removed
>  Sean> from a weak table.
> 
> I think you're missing the point - it's enough _now_, it's not enough in
> the presence of hypothetical optimizations that treat a variable as dead
> after it is referenced for the last time.

  Thanks for the clarification.

  I can think of one potential way:

	local a = weaktable[x]
	-- code code code
	weaktable[x] = a

  This may be enough to keep a alive, depending upon how the hypothetical
optimizer works.  Or, taking an idea from C's "volatile" (but changing the
name):

	local <noopt> a = weaktabke[x]

  We have this new syntax to play around with ...

  -spc