lua-users home
lua-l archive

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


>I would like to know if when I execute the code shown below, the garbage
>collector can "clean" the lost data.

By definition, GC clean *all* lost data.

>x = {}
>x[{}] = 1 -- lost data

What lost data here? The {} in x[{}] = 1 is kept as long as the 1 stays in x.
BTW, why not write
	x={}
	x[x]=1

>when this object is
>destructed I want that your private data also be destructed.

Yes, if no one else points to the private data.

>function Public:new()
>  local t = {}
>  settag(t, tag(%Public))
>
>  -- initialize private data
>  %Private[t] = {}
>  %Private[t].balance = 0
>
>  return t
>end

Ah, you mean to remove the t entry in Private when t is collected?
In Lua 3.2 you can set the "gc" tag method of t so that it removes the entry
in Private. In 4.0, this is no longer allowed but perhaps it will in 4.1.
--lhf