lua-users home
lua-l archive

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


On Mon, Jun 3, 2019 at 11:03 AM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
> I fully agree. Even in C++ and Java that have weak references, as soon as the reference is no longer used, the object can be garbage collected

I'm not going to dwelve into Java, but STDCPP has no "weak
references". It has weak pointers, which have a precisely defined
semantic, which is what lua has now. You make a weak ptr from a shared
ptr, weak ptr is alive as long as any shared ptr from the set is
alive, shared ptr are normal objects ( that's one of the beauties of
RAII and proper objects ), and they are destroyed when they go out of
scope.

> (well, weak references can even be collected before the variable goes out of scope, and even if it is accessed later in the same scope, in which case there will be an exception or wrapper to reconstruct it, this is typically for objects that are local caches of data infered from a remote object, or which is slow to load via some I/O or recomputing).

You are inventing and mixing concepts there.

> Java and C/C++ compilers also perform "deletion" of unused variables, by reusing their storage slots for other variables.

Yes, but they are careful to preserve the semantics of the language.
> That's the purpose of the data flow analysis performed by the compiler and it saves a lot of run time space. Only a unoptimized version for debugging (or an interpreted version based on reflection, because one inserted a variable tracker in the debugger and the programmer wants to preserve their value somewhere in a scratchpad of the debugger) will preserve these unused slots.

That "unused slots" stuff is "compiler-fiction". They are complicated
beasts. And I insure you they do not work that way, make some programs
with some non trivial destructors, optimize, dissasemble and see.

Francisco Olarte.