|
This doesn't need to be something manually specified.You haven't mentioned which version of lua use are using.Lua 5.2 had an optional generational garbage collector, which does what you describe.Try running your code with it on. From lua: collectgarbage("generational")However, it was removed in 5.3 due to lack of positive results (well, as far as I understood it, lack of *any* useful reports)On 30 May 2016 at 09:57, Rodrigo Azevedo <rodrigoams@gmail.com> wrote:Is this possible?Then, each object into this table (keys and values) will be scanned by GC "almost never". This can alleviate the work of GC, and keep the memory usage more straight.where 'l' means 'long lived'maybe an orthogonal idea:setmetatable({},__mode='l')2016-05-29 4:39 GMT-03:00 zejian ju <juzejian@gmail.com>:You can try luarc (https://github.com/zenkj/luarc-5.1), Refcount GC is added upon the normal incremental Mark&Sweep GC.The result:> time ./lua test.lua262172.40332031464729.12695312real 13m44.993suser 13m38.374ssys 0m0.747s> time ./luarc test.lua262184.49316406262184.49316406real 4m36.861suser 4m37.461ssys 0m0.137s2016-05-29 1:03 GMT+08:00 Rodrigo Azevedo <rodrigoams@gmail.com>:The code
N = 1.0e7
C = {}
for i=1,N do C[i] = i end
print(collectgarbage("count"))
for i=1,100*N do
local a = {1,2,3,4}end
print(collectgarbage("count"))prints262166.11035156445760.78710938problem: when Lua uses lot of memory, the creation of temporary objects can consume all your memory. I think CG should collect the objects fast enough, but it does not. A perfectly OK program can't run because of the amount of garbage to be collected consumes all memory.I overcome this situation using collectgarbage() options inside the "for", but the performance is severely degraded. (due to the high number of objects GC need to manager, or the manual increase of the number of cycles.)question: There is some place of Lua source code that I can modify to keep the memory usage as close as possible to 262166.11035156 without doing my program 3x slowly?
--Rodrigo Azevedo Moreira da Silva
--Rodrigo Azevedo Moreira da Silva