lua-users home
lua-l archive

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


On Dec 19, 2013, at 9:39 PM, Sean Conner <sean@conman.org> wrote:

>  Furthermore, you do not need a loop:

Well… at least Roberto’s little memory monitor [1] does catch this: 

lua: error in __gc metamethod (TestConfig.lua:11: script uses too much memory)


[1] 

—8<—
do
  -- track memory use
  local mt = {__gc = function (u)
    if collectgarbage("count") > 10000 then
      error("script uses too much memory")
    else
      setmetatable({}, getmetatable(u))
    end
  end}
  setmetatable({}, mt)
end
—>8—