# GC "hints" needed from rg2, to free up memory?

**URL:** <https://www.ruby-forum.com/t/gc-hints-needed-from-rg2-to-free-up-memory/108135>\
**Category:** Ruby-Gnome 2\
**Created:** [June 29, 2007, 9:58am UTC](https://www.ruby-forum.com/t/gc-hints-needed-from-rg2-to-free-up-memory/108135 "2007-06-29T09:58:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [June 29, 2007, 9:58am UTC](https://www.ruby-forum.com/t/gc-hints-needed-from-rg2-to-free-up-memory/108135/1 "2007-06-29T09:58:49Z")

</div>

I’m currently coding a new program, which opens a lot of large images  
(photos) with Gdk::Pixbuf. These are “freed up” correctly (no more  
alive reference to the object in my program), but the ruby program is  
never freeing memory to the OS, unless I explicitely trigger the GC.  
This is a big problem as the computer crawls swapping after a little  
while 😕

I am wondering whether there should be some kind of GC “hints” from  
rg2 (I have zero knowledge of ruby GC internal)? The following quick  
test shows that repeatedly allocating and reassigning with Array.new  
grows memory up until a “reasonable” amount, whereas Gdk::Pixbuf.new  
does not:

[http://zarb.org/~gc/t/tmem.rb.out](http://zarb.org/~gc/t/tmem.rb.out)  
[http://zarb.org/~gc/t/tmem.rb](http://zarb.org/~gc/t/tmem.rb)

Used image is [http://zarb.org/~gc/t/pa.jpg](http://zarb.org/~gc/t/pa.jpg)

(using ruby 1.8.6, rg2 0.16.0, gdk pixbuf 2.10.12)

–  
Guillaume C. - [http://zarb.org/~gc/](http://zarb.org/~gc/)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [June 29, 2007, 11:02am UTC](https://www.ruby-forum.com/t/gc-hints-needed-from-rg2-to-free-up-memory/108135/2 "2007-06-29T11:02:55Z")

</div>

Hi,

yesterday i had exactly the same problem. I pumped up to several hundred  
pixbufs of 640x480 troug a Gtk::Image. I coul follow like the memory got  
eaten and than the application got stuck caus the swap got active.

My solution was to put a GC.start after the assignement of every new  
pixbuf to the image. That solved the problem nearly completly and for  
the performance it was also no problem.

But i think, that is not the right way.

Cheers  
detlef

Am Freitag, den 29.06.2007, 09:58 +0200 schrieb Guillaume C.:

> grows memory up until a “reasonable” amount, whereas Gdk::Pixbuf.new  
> does not:
> 
> [http://zarb.org/~gc/t/tmem.rb.out](http://zarb.org/~gc/t/tmem.rb.out)  
> [http://zarb.org/~gc/t/tmem.rb](http://zarb.org/~gc/t/tmem.rb)
> 
> Used image is [http://zarb.org/~gc/t/pa.jpg](http://zarb.org/~gc/t/pa.jpg)
> 
> (using ruby 1.8.6, rg2 0.16.0, gdk pixbuf 2.10.12)

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)
