rlua icon indicating copy to clipboard operation
rlua copied to clipboard

Lua::Function and Lua::Table leaking memory

Open krissi opened this issue 8 years ago • 1 comments

It seems that Lua::Function and Lua::Table are never getting removed from memory. Lua::State is only removed when manually removing all references.

require 'rlua'

def stressloop_for(c, *klasses)
  GC.start
  GC.stress = true
  c.times do
    yield
  end
  GC.stress = false
  GC.start

  klasses.each do |klass|
    puts "Instances of #{klass}: #{ObjectSpace.each_object(klass).count}"
  end
end

stressloop_for(10, Queue) do
  q = Queue.new
  q << 'hi'
end
# => Instances of Queue: 0

stressloop_for(10, Lua::State, Lua::Function, Lua::Multret, Lua::Table) do
  s     = Lua::State.new
  s.add = ->(a, b) { a+b }
  s.__eval('return(add(1,1))')
end
# => Instances of Lua::State: 10
# => Instances of Lua::Function: 10
# => Instances of Lua::Multret: 0
# => Instances of Lua::Table: 10

stressloop_for(10, Lua::State, Lua::Function, Lua::Multret, Lua::Table) do
  s     = Lua::State.new
  s.add = ->(a, b) { a+b }
  s.__eval('return(add(1,1))')
  s = nil
end
# => Instances of Lua::State: 10
# => Instances of Lua::Function: 20
# => Instances of Lua::Multret: 0
# => Instances of Lua::Table: 20

krissi avatar Feb 03 '17 16:02 krissi

Unfortunately I use neither Ruby nor Lua for years at this point. Don't expect me to fix this, although I will of course help you and/or review any resulting PR.

whitequark avatar Feb 03 '17 18:02 whitequark