Removing signal handlers - is it necessary?

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=sourceforge&CID=DEVDEV

On Tue, Mar 13, 2007 at 10:39:56AM +0000, Martin P. 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=sourceforge&CID=DEVDEV