[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: calling collectgarbage in __gc metamethod
- From: Atilim Cetin <atilim.cetin@...>
- Date: Mon, 6 Aug 2012 23:48:40 +0300
On Mon, Aug 6, 2012 at 10:57 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> I've just met this interesting behavior while writing my Box2d
>> wrapper. I don't know if it's a bug or not but Lua 5.1.4 avoids GC
>> steps while running a __gc metamethod.
>
> The next example calls collectgarbage inside a __gc metamethod without
> any problems (at least in my machine):
>
> -------------------------------
> u = newproxy(true)
> getmetatable(u).__gc = function (o)
> print("start gc", o)
> collectgarbage()
> print("end gc", o)
> end
>
> for i = 1, 10 do
> u = newproxy(u)
> print("creating", u)
> end
>
> collectgarbage()
> -------------------------------
>
> So, either you hit a more strange bug in Lua or the crashing is in
> your code.
>
> -- Roberto
>
>
Yes crashing is in my code. In my case, when a __gc metamethod is
called inside another __gc metamethod, my code crashes. Because in the
middle of destruction of one of my objects, another destruction is
initiated.
Here the output is like:
start gc
start gc
start gc
....
end gc
end gc
end gc
But I expected:
start gc
end gc
start gc
end gc
start gc
end gc
....