Missing Ruby objects reference RubyVm :: Env

I track the memory leak problem in our application (ruby 2.1). I use both methods: ObjectSpace.dump_all to dump all objects into a JSON stream, then do offline analysis. The second method I used was real-time analysis using ObjectSpace.reachable_objects_from . In both cases, I found that my leaked objects reference a RubyVM::Env object. Anyone can explain to me what RubyVM::Env . How to remove these links?

+6
source share
1 answer

RubyVM::Env is an internal ruby ​​class that contains variable references. Here is my test:

 require 'objspace' a = Object.new a_id = a.object_id # we use #object_id to avoid creating more reference to `a` ObjectSpace.each_object.select{ |o| ObjectSpace.reachable_objects_from(o).map(&:object_id).include?(a_id) }.count # => 1 env = ObjectSpace.each_object.select{ |o| ObjectSpace.reachable_objects_from(o).map(&:object_id).include?(a_id) }.first # => #<RubyVM::Env:0x007ff39ac09a78> ObjectSpace.reachable_objects_from(env).count # => 5 a = nil # remove reference ObjectSpace.reachable_objects_from(env).count # => 4 
+1
source

Source: https://habr.com/ru/post/988745/


All Articles