Skip to content

Lua::Function and Lua::Table leaking memory #9

@krissi

Description

@krissi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions