lua-users home
lua-l archive

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

在 2017/2/4 19:40, Uli Schlachter 写道:
> Hi there,
> I came across a supposed leak[1,2] with some C code. I think I distilled
> the behaviour that causes problems into the attached Lua program and
> would now like to get some input on "which code is to blame".
> I noticed that the problem occurs with Lua 5.3, but does not occur with
> Lua 5.1 or 5.2. Thus, I could do a Git bisect based on the GitHub mirror
> of the Lua source code[3]. The result is that commit [4] introduced the
> problem.
> My main question now is: What to do about this?
> Some more information about the program: The library in question
> provides bindings to GObject-based C libraries. To support callbacks, it
> has to luaL_ref() the callback function and it will then luaL_unref()
> later from the __gc metamethod of some of the involved object.
> This is just what the attached program does: In a tight loop, it creates
> a table, luaL_ref()s it and arranges for a call to luaL_unref() later.
> Apparently the code can now create references faster than they are released.
> I hope this is enough information to help me. Thanks for any hints and
> suggestions that you might have!
> Cheers,
> Uli
> [1]:
> [2]:
> [3]:
> [4]:

after some experiments with the attached code, it seems in Lua 5.3 the collector can't catch up with the mutator.
maybe the debt calculation algorithm has some kind of flaw?

here is my result:

on my machine, the original attached script would report as

   ``lua: leak.lua:53: too much memory used after 38.6``

if I add this line

   ``collectgarbage("setpause", 190)``

it will report at 46.3

set pause to 170, the error report at 98.7

after I set gc pause to 160, the memory usage of the sample script won't go unlimited.

while in Lua 5.2 with the default gc pause value 200, the script runs just fine.

I suppose this might potentially be defect of the GC.
more investigation is needed to track down the problem.
the nerdy Peng / 书呆彭 /