Hello,
I am having some object lifetime issues with events in IronRuby.  I think I
have a repro, so bear with me.  The problem seems to be that the proc seems
to have a bunch of extra "stuff" in its execution environment.

Consider the following ruby code:

require "System.Windows.Forms"
include System::Windows::Forms
include System

class Tester
  attr_reader :wc


  def test
    @wc = WeakReference.new(Button.new)
    add_handler
  end

  def add_handler
    # if we uncomment the following two lines out, and comment out the last
line, the Button will leak and not
    # be cleaned up even though there should be no live references to it
    #...@handler = lambda {|*a| puts "text changed" }
    #[email protected]_changed.add @handler
    @wc.target.text_changed.add lambda {|*a| puts "text changed" }
  end
end

t = Tester.new
t.test
System::GC.collect
puts "wc is alive = #{t.wc.is_alive}" # this should always print false


If you uncomment the two lines indicated in add_handler, the button in the
weak reference will leak. I think that this is incorrect.  The proc object
(and its associated binding) shouldn't have any live references to
@wc.target.  I'm not 100% sure, but this makes it a bit harder if we want to
be able to detach the proc later.

Any thoughts?
Thanks!
Martin
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to