On Fri, Jul 25, 2014 at 8:30 PM, Mike Pall <mike-1407@xxxxxxxxxx> wrote: > Valerio Schiavoni wrote: >> On my machine (Mac OSX 10.9), LuaJIT 2.1 (freshly cloned) crashes more >> or less around the the time the program prints '651' (thought slight >> variations might occur). >> LuaJIT 2.0.3 works just fine. > > I get the out-of-memory condition in various versions and 32/64 bit > variants, just at different places. It may happen for plain Lua, too. I could not reproduce it with plain Lua 5.2.3, at least not on mac osx 10.9 or ubuntu 14 lts. > The Lua/LuaJIT garbage collector is only driven forward on regular > allocations, but not when growing a table. > > There are only two allocations here: the 'local i_dist={}' and the > implicit string creation in 'print(i)'. LuaJIT doesn't even need an > allocation for the latter, i.e. it only performs half the GC steps. > > But there are lots of table growths inbetween. So, even if the GC > starts a cycle at some point in time, it may not catch up and > perform enough incremental steps to complete the cycle before > memory runs out. > > There have been various reports on the Lua mailing list about this > issue, esp. with big userdata allocations. IMHO it's quite > difficult to modify the current GC to handle that better. Tuning > GC heuristics to perform well under all kinds of mutator loads is > really, really hard. Would you suggest, as possible workaround, a pre-allocation of the i_dist table with nil values, thus avoiding the table growths during the iteration ? Would that somehow help the luajit vm ? Thanks, Valerio