# Ruby-gnome2's effects on garbage collection time

**URL:** <https://www.ruby-forum.com/t/ruby-gnome2s-effects-on-garbage-collection-time/115828>\
**Category:** Ruby-Gnome 2\
**Created:** [September 28, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/ruby-gnome2s-effects-on-garbage-collection-time/115828 "2007-09-28T21:53:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_McIntosh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@Ian\_McIntosh](https://www.ruby-forum.com/u/Ian_McIntosh)\
**Post date:** [September 28, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/ruby-gnome2s-effects-on-garbage-collection-time/115828/1 "2007-09-28T21:53:40Z")

</div>

Hi all,

I’ve created two little demo applications that demonstrate how loading  
the ruby-gnome2 bindings (without even using them) seems to have an  
extremely detrimental effects on Ruby’s garbage collection time.

# ============================================== A test program NOT using ruby-gnome2 bindings:

module ObjectSpace  
def self.object\_count(base\_class = Object)  
count = 0  
each\_object(base\_class) { count += 1 }  
return count  
end  
end

# Toss some junk in the trunk

trunk = []  
strs = (‘a’…‘z’).to\_a  
100.times do  
trunk \<\< (1…1000).collect { strs[rand(strs.size)] +  
strs[rand(strs.size)] } # …random combinations…  
puts “#{ObjectSpace.object\_count} objects, #{start = Time.now ;  
GC.start ; Time.now - start} GC time, #{ObjectSpace.object\_count}  
remain”  
end

# ============================================== Output:

1436 objects, 0.001289 GC time, 1424 remain  
…  
5432 objects, 0.002776 GC time, 5430 remain  
…  
100527 objects, 0.032424 GC time, 100525 remain

Note 0.0028 for 5k objects, 0.032 seconds for 100k objects

# ============================================== Now, a new program using ruby-gnome2 bindings:

module ObjectSpace  
def self.object\_count(base\_class = Object)  
count = 0  
each\_object(base\_class) { count += 1 }  
return count  
end  
end

require ‘gtk2’

# No junk, no trunk, just the bindings loaded

5.times do  
puts “#{ObjectSpace.object\_count} objects, #{start = Time.now ;  
GC.start ; Time.now - start} GC time, #{ObjectSpace.object\_count}  
remain”  
end

# ============================================== Output:

11639 objects, 0.015278 GC time, 5168 remain  
5170 objects, 0.018248 GC time, 5167 remain  
5169 objects, 0.063149 GC time, 5167 remain  
5169 objects, 0.060721 GC time, 5167 remain  
5169 objects, 0.060337 GC time, 5167 remain

First of all, we’re seeing many thousand new objects before _using_ the  
library at all. This increases the time for every future GC run, so it  
would be nice to reduce this.

But more importantly, with the GTK bindings loaded, only 5k objects  
takes 0.06 seconds to GC. It’s almost twice as long as GC’ing 100k  
objects without the GTK bindings loaded!

And this is before creating a single GTK widget…

This issue makes doing any sort of animation in a Ruby/GTK app  
tremendously frustrating, as even a lowly 24fps requires doing a frame  
every 0.04 seconds, and right from the start a Ruby/GTK app’s GC  
operation pauses the entire app for 0.06 seconds. (And with a full GTK  
GUI loaded and around 16k objects, a Ruby/GTK app’s GC time reaches 0.2  
seconds!)

Any ideas as to why the ruby-gnome2 bindings have this effect and how we  
can reduce/eliminate it?

Cheers,  
-Ian
