lua-users home
lua-l archive

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




On Wed, Jul 18, 2018 at 12:18 PM, Gé Weijers <ge@weijers.org> wrote:

On Wed, Jul 18, 2018 at 9:19 AM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
We had something (scope-qualified locals) that seemed to be enough.
Now we have this list of problems:

- It does not create a new scope by itself;
- It is not visible enough;
- It still does not solve the problem for global variables;
- It cannot supress exceptions.

The better is the enemy of the good here. I've seen many programs that leak memory, even though they were written in a language that uses a garbage collector (forgot to set that object member to nil?). Garbage collection is a 95% solution, you have to know how it works and sometimes you have to tweak things.

The problem of leaking resources is a real one, and the implementation of a generational garbage collector in Lua 5.4 may make them worse by making the object owning the resource extremely long-lived once it leaves the nursery.  Scoped locals, a "with ... as" clause, or an equivalent construct can make the programmer's job easier, but there is no 100% solution. A 100% solution would solve the halting problem :-)


--
--



And this is where I'm not seeing what others are seeing.

Is performance the issue or order?

If order is not the issue, then calling collectgarbage("collect") after setting your objects to `nil` would be all that is required. Is that correct?

If performance is the issue, then I what is the data on that?

From my vantage point, it looks like the problem to solve is:

There is no simple and robust way to destroy objects that:
 1: have allocated resource that cannot remain allocated for indeterminate amounts of time
 2: need to be destroyed in a specified order
 3: to do so even when something goes wrong, every time

Is that the problem to be solved? Who is the target for this feature? A person informally acquainted with programming or someone writing Lua libraries?

--
Andrew Starks