[jruby] A little test for possible memory leaks

david brometeo at gmail.com
Mon Jan 15 20:25:39 JST 2018

Hi all.

I have some code for evaluating. Here you have:

require 'pry'
class Foo
  def define_bar_method(&block)
    define_singleton_method(:bar, &block)
  def remove_bar_method
    singleton_class.class_eval do
      remove_method :bar
foo = Foo.new
foo.deine_bar_method {2 + 2}
foo = nil

As you can see, I have defined a stop point with "pry". in that point, foo
object in not assigned to any variable, so I think that a Garbage Collection
from visualvm should remove it from memory. If you try, you'll see object is
not removed and I think the problem is in binding done by singleton method
"bar". As I have removed bar method previously, I don't understand what is
avoiding garbage collecting :(

Can you help me with this simple case? Thank you very much in advance.


P.D: Sorry about message proliferation. I was subscribed in digest mode, so it
was difficult go with the thread. Now I am not in digest, so I think it will be
easier and cleaner going with discussion.


More information about the JRuby mailing list