# Garbage-collection question OR ruby-gnome bug?

**URL:** <https://www.ruby-forum.com/t/garbage-collection-question-or-ruby-gnome-bug/60099>\
**Category:** Ruby\
**Created:** [May 10, 2006, 7:09am UTC](https://www.ruby-forum.com/t/garbage-collection-question-or-ruby-gnome-bug/60099 "2006-05-10T07:09:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cam](https://www.ruby-forum.com/u/cam)\
**Post date:** [May 10, 2006, 7:09am UTC](https://www.ruby-forum.com/t/garbage-collection-question-or-ruby-gnome-bug/60099/1 "2006-05-10T07:09:36Z")

</div>

Hi,

My friend and I have been writing an application that makes extensive  
use of gdkpixbuf’s, but they never get de-allocated. I’m not entirely  
sure how the garbage-collector works internally in ruby, but my  
program quickly grows to over 114M pretty routinely. My friend wrote  
a simple demonstration script:

require ‘gtk2’  
Gtk.init  
path = ARGV.pop  
raise “Pass a large image on the command line” unless path  
puts “Look at how much memory I’m using, then press enter”  
gets #1  
buf = Gdk::Pixbuf.new( path )  
puts “Now I’ve allocated the pixbuf, I should be using more memory.”  
puts “Hit enter to dereference the pixbuf.”  
gets #2  
buf = nil  
puts “Done. Press enter to exit.”  
gets #3

Ok, here’s the memory usage between various stages:

1:  
1000 17271 0.3 2.4 15744 9312 pts/5 S+ 23:03 0:00 ruby  
pixbuf.rb

2:  
1000 17271 0.3 4.1 22448 16228 pts/5 S+ 23:03 0:00 ruby  
pixbuf.rb

3:  
1000 17271 0.3 4.1 22448 16228 pts/5 S+ 23:03 0:00 ruby  
pixbuf.rb

Now this example is much more trivial than the program we’re trying to  
right, but they’re both having this issue w/ the pixbuf’s never being  
de-allocated. Is this a known bug? Is there something we can do to  
force the GC to take care of them?

Thanks,  
Cameron M.

---

<div class="post-metadata">

**Author:** ![cam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cam](https://www.ruby-forum.com/u/cam)\
**Post date:** [May 10, 2006, 9:08am UTC](https://www.ruby-forum.com/t/garbage-collection-question-or-ruby-gnome-bug/60099/2 "2006-05-10T09:08:29Z")

</div>

2006/5/10, Cam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> path = ARGV.pop
> 
> Now this example is much more trivial than the program we’re trying to  
> right, but they’re both having this issue w/ the pixbuf’s never being  
> de-allocated. Is this a known bug? Is there something we can do to  
> force the GC to take care of them?

I can only say something about your short demo piece because I don’t  
have the other code. It’s quite unlikely that you see the GC kick in  
before program termination here. GC kicks in when the interpreter  
decides to do it - not necessarily soon after an object has become  
unreachable. This is really only a problem if you have a long running  
version and it keeps using more memory over time. I suggest you  
modify your script by removing lines with “gets” and put the whole  
thing in a loop say 10,000 times. Then watch how memory usage  
develops. If it’s linearly increasing your chances are that there is  
a bug in Gdk or you’re using it the wrong way (i.e. do not release Gdk  
resources as required by the lib).

HTH

robert

---

<div class="post-metadata">

**Author:** ![cam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cam](https://www.ruby-forum.com/u/cam)\
**Post date:** [May 10, 2006, 9:44pm UTC](https://www.ruby-forum.com/t/garbage-collection-question-or-ruby-gnome-bug/60099/3 "2006-05-10T21:44:09Z")

</div>

Hey,

On 5/10/06, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> resources as required by the lib).  
> I had thought about the GC not having time to free up the resources,  
> but I assumed that the GC would start doing its magic whenever the  
> program was idle. Anyway, the real program is much more complex than  
> this, and it should be having plenty of time for GC. Is it common for  
> a library to require releasing of resources? I will look into that  
> further, although I don’t _think_ i saw anything about that in the  
> docs.

Thanks,  
Cameron M.
