[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __mode="k"
- From: Edgar Toernig <froese@...>
- Date: Wed, 7 Apr 2004 13:59:34 +0200
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.