lua-users home
lua-l archive

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


Le lun. 3 juin 2019 à 11:20, Francisco Olarte <folarte@peoplecall.com> a écrit :
Philippe:

On Mon, Jun 3, 2019 at 1:28 AM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
> Le dim. 2 juin 2019 à 17:15, Andrew Gierth <andrew@tao11.riddles.org.uk> a écrit :
>> But even in the absence of finalizers, holding a (strong) reference to
>> an object has a visible effect: it prevents the object from vanishing
>> from a weak table due to collection. So the actual lifetime of a local
>> variable matters, even if its value is never fetched.

> Yes but you don't define what is the "lifetime". For me a variable that is never fetched is already dead, it has NO value to keep it in "life" longer than needed.

Values lifetime is what worries me ( a variable may be dead, its value
may be alive if it is in another variable ).

 It's also what I mean. But a "variable" is the storage slot where the value or a reference to the value is kept.
If the value is in another variable (i.e. a distinct storage for the value or its reference), then it has a new reference.
But the old variable that contained that value does not matter: if it goes out of scope (because if it no longer accessed, then there remains not 2 references but 1 (in the other variable).
That first variable can then be freed/deleted/unallocated or reused for something else, it won't affect the value that may still be live in the separate variable.

And this is not "strange": there are two kinds of lifetimes: one for the variable (its scope of visibility and access)  and another for the value. Both are tied together only for values of simple types (in Lua, these are only numbers and nil, because all other types are references to the object-type or string-type value stored separately, outside the slot of any variables).