# Toggle references

**URL:** <https://www.ruby-forum.com/t/toggle-references/189826>\
**Category:** Ruby-Gnome 2\
**Created:** [June 8, 2010, 1:52pm UTC](https://www.ruby-forum.com/t/toggle-references/189826 "2010-06-08T13:52:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/838e76/32.png) [@yonkey](https://www.ruby-forum.com/u/yonkey)\
**Post date:** [June 8, 2010, 1:52pm UTC](https://www.ruby-forum.com/t/toggle-references/189826/1 "2010-06-08T13:52:33Z")

</div>

Hi,

I filed a bug report with two patches for using toggle references for  
the GObject memory management in ruby-gnome2. I just thought I’d send a  
note to this list as well in case the Bugzilla isn’t often checked.

[https://sourceforge.net/tracker/?func=detail&aid=3012947&group\_id=53614&atid=470969](https://sourceforge.net/tracker/?func=detail&aid=3012947&group_id=53614&atid=470969)

Has this been discussed anywhere before? It seems like it would be more  
robust than having to walk the entire hierarchy of objects in the mark  
phase. As far as I can see Ruby is unique in using this method to bind  
GObjects. pygtk, gjs, seed, Gtk# and java-gnome all use toggle  
references.

Regards,

- Neil

---

<div class="post-metadata">

**Author:** ![yonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/838e76/32.png) [@yonkey](https://www.ruby-forum.com/u/yonkey)\
**Post date:** [June 8, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/toggle-references/189826/2 "2010-06-08T14:31:46Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] Toggle references” on Tue, 08 Jun 2010  
12:17:49 +0100,  
Neil R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> references.  
> If the method is a better method rather than the current  
> method, we will use the method. Did you confirm that your  
> patches don’t cause new SEGVs and/or memory leaks? If you  
> already confirmed it, please show the detail. If you need  
> more time to confirm it, you can do it in the official  
> repository.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![yonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/838e76/32.png) [@yonkey](https://www.ruby-forum.com/u/yonkey)\
**Post date:** [June 8, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/toggle-references/189826/3 "2010-06-08T15:08:40Z")

</div>

Neil R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I filed a bug report with two patches for using toggle references…

Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If the method is a better method rather than the current method, we  
> will use the method. Did you confirm that your patches don’t cause new  
> SEGVs and/or memory leaks? If you already confirmed it, please show  
> the detail. If you need more time to confirm it, you can do it in the  
> official repository.

I did some minor testing to confirm that it doesn’t memory leak by  
creating a simple script and stepping through it with GDB to check that  
the ref counts are correct and that the mark phase is executed. I also  
ran it with gtk-demo and it didn’t seem to cause any problems. Of course  
it’s quite a tricky thing to be sure about so I may have missed  
something. Are there any standard tests with ruby-gnome2 to stress the  
ref counting?

I will try to make a more formal test with a write-up when I get the  
chance.

Thanks

- Neil

---

<div class="post-metadata">

**Author:** ![yonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/838e76/32.png) [@yonkey](https://www.ruby-forum.com/u/yonkey)\
**Post date:** [June 9, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/toggle-references/189826/4 "2010-06-09T16:30:47Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Toggle references” on Tue, 08 Jun 2010  
14:08:07 +0100,  
Neil R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it’s quite a tricky thing to be sure about so I may have missed  
> something. Are there any standard tests with ruby-gnome2 to stress the  
> ref counting?
> 
> I will try to make a more formal test with a write-up when I get the  
> chance.

There are no standard tests to stress the ref counting but I  
use the following test:

1. select an application (e.g. demo.rb. See also  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Applications](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Applications)  
I’m using Rabbit for it.)
2. create stress.rb that has the following content:  
Thread.new do  
loop do  
GC.start  
sleep 1  
end  
end
3. run an application with the following command:  
% ruby -I. -r stress application.rb

The above test will stress to application.rb. You may find  
some bugs with a standard application usage on the stress  
environment.

## Thanks,

kou
