A simple test case without upvalues... Works Ok with -joff local ffi=require('ffi') local function object(n) local r={ b=ffi.new('uint8_t[?]',n*n) } function r.test(n) for i=0,n do r.b[0]=0 end end return r end local o=object(1024) --o.test(50) -- this works o.test(100) -- Memory leak o=nil for i=1,10 do collectgarbage('collect') print(collectgarbage('count')) end 2012/8/27 Juan Carlos González Amestoy <jcgamestoy@xxxxxxxxx> > I think i find a bug in luajit. > > On the following code: > > local ffi=require('ffi') > > local function buffer(n) > return ffi.new('uint8_t[?]',n) > end > > local function object(n) > local b=buffer(n*n) > > local function test(n) -- if n>50 memory leak. > for i=0,n do b[0]=0 end > end > > return { > b=b, > test=test > } > end > > local function testCreate() > local o=object(1024) > > o.test(50) > o.test(100) -- if comment this line memory is released. > end > > testCreate() > > for i=1,10 do > collectgarbage('collect') > print(collectgarbage('count')) > end > > > If i call the 'test' method with a value greater than 50 the memory buffer > is never released (the print line prints >1000kb). > > I test this in Mac Os X x64 and Linux x64. > > PD: Sorry for the bad english > > -- > Juan Carlos González Amestoy > > > -- Juan Carlos González Amestoy (Servicio Informática Universidad de Alicante)