> I could not reproduce it with plain Lua 5.2.3, at least not on mac osx > 10.9 or ubuntu 14 lts. On debian 7: ➜ all-distance git:(master) lua -v Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio ➜ all-distance git:(master) lua alldistances.lua ... 830 831 832 lua: not enough memory Next trying lua 5.2 (after some apt-get juggling): ➜ all-distance git:(master) lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio ➜ all-distance git:(master) lua alldistances.lua ... 10923 ... and counting (no crash yet) So it seems that either lua 5.2 received some changes to the garbage collector, or it's a fluke. Since you couldn't reproduce it either I would go with gc changes.