lua-users home
lua-l archive

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


Nodir Temirhodzhaev wrote:
>
> Why in weak keyed table userdata's not autocollect?
> 
> ---
> local k = io.open("test", "w")
> local w = setmetatable({[k] = 1}, {__mode = "k"})
> k = nil; collectgarbage()
> table.foreach(w, print)
> ---
> Prints:
> file (closed)  1
> 
> But if k is table or thread then prints nothing.

Collecting userdata with gc-methods requires two
collectgarbage runs.  On the first, the gc-method
is executed (file closed), on the second the user-
data is freed (includes removing weak keys).

Ciao, ET.