Forum: Ruby-Gnome 2 Removing signal handlers - is it necessary?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
35f0e7653d7404ac987b0383e1d76e2e?d=identicon&s=25 Martin Portman (Guest)
on 2007-03-13 11:40
(Received via mailing list)
Hi,

With something like:

 class Box < Gtk::HBox
  def initialize
    super( false )
    @dummy = []

    button = Gtk::Button.new("Hello")
    button.signal_connect("clicked"){
  @dummy << 'hello'
    }
    pack_start( button )
    button.show
  end
 end

Does the proc object, which is the signal handler for button, create a
'memory
leak' when I try to 'destroy' a Box?

In other words, do I need to store the handler_id, and then disconnect
it
when I no longer need the instance of Box?

And does the content of the proc matter?  Ie. if it didn't reference
@dummy, would
things be better?

Cheers,
Martin.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p...
6bf57b10a0d04acd62b9d83a8a791327?d=identicon&s=25 unknown (Guest)
on 2007-03-13 11:56
(Received via mailing list)
On Tue, Mar 13, 2007 at 10:39:56AM +0000, Martin Portman wrote:
>     button.signal_connect("clicked"){
> In other words, do I need to store the handler_id, and then disconnect it
> when I no longer need the instance of Box?

The lifetime of your proc object here is directly bound to the lifetime
of the
button since ruby-gnome2 0.15.0. Thus there is no need to disconnect it.

> And does the content of the proc matter?  Ie. if it didn't reference @dummy,
> would things be better?

The proc object only references what's inside it, not the other way
around. So
it doesn't matter.

  Sjoerd
--
The universe is made of stories, not of atoms.
    -- Muriel Rukeyser

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p...
This topic is locked and can not be replied to.