# Removing signal handlers - is it necessary?

**URL:** <https://www.ruby-forum.com/t/removing-signal-handlers-is-it-necessary/88658>\
**Category:** Ruby-Gnome 2\
**Created:** [March 13, 2007, 11:40am UTC](https://www.ruby-forum.com/t/removing-signal-handlers-is-it-necessary/88658 "2007-03-13T11:40:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [March 13, 2007, 11:40am UTC](https://www.ruby-forum.com/t/removing-signal-handlers-is-it-necessary/88658/1 "2007-03-13T11:40:47Z")

</div>

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](http://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](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [March 13, 2007, 11:56am UTC](https://www.ruby-forum.com/t/removing-signal-handlers-is-it-necessary/88658/2 "2007-03-13T11:56:49Z")

</div>

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](http://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](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
