# Memory leak in Gdk::Pixbuf.from\_drawable

**URL:** <https://www.ruby-forum.com/t/memory-leak-in-gdk-pixbuf-from-drawable/180167>\
**Category:** Ruby-Gnome 2\
**Created:** [December 14, 2009, 12:36am UTC](https://www.ruby-forum.com/t/memory-leak-in-gdk-pixbuf-from-drawable/180167 "2009-12-14T00:36:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias\_LSSS\_tke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85e7bf/32.png) [@Tobias\_LSSS\_tke](https://www.ruby-forum.com/u/Tobias_LSSS_tke)\
**Post date:** [December 14, 2009, 12:36am UTC](https://www.ruby-forum.com/t/memory-leak-in-gdk-pixbuf-from-drawable/180167/1 "2009-12-14T00:36:57Z")

</div>

Hi Gdkers,

I’m working on a website screenshotting service and I’m using a rack +  
motzembed solution. Works really well except for one memory leak:

Either i’m missing a way to tear down the images that come from a  
Pixbuf.from\_drawable or ruby-gnome2 somehow keeps a permanent pointer  
to the allocated image. The code below can fill up my 4gb of memory in  
about 30 secs.

Anyone got a workaround? Maybe an alternative way to get a png  
screenshot of a window?

require ‘rubygems’  
require ‘gtk2’

@window = Gtk::Window.new  
@window.set\_size\_request 1024, 768

# Connect signals

@window.signal\_connect(“destroy”) { Gdk.main\_quit }  
@window.show\_all

Gtk::timeout\_add(50) do  
width, height = @window.size  
window = @window.window

Gdk::Pixbuf.from\_drawable(window.colormap, window, 0, 0, width, height)

true  
end

Gtk.main

Regards  
– tobi

---

<div class="post-metadata">

**Author:** ![Tobias\_LSSS\_tke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85e7bf/32.png) [@Tobias\_LSSS\_tke](https://www.ruby-forum.com/u/Tobias_LSSS_tke)\
**Post date:** [December 15, 2009, 9:38am UTC](https://www.ruby-forum.com/t/memory-leak-in-gdk-pixbuf-from-drawable/180167/2 "2009-12-15T09:38:37Z")

</div>

Hi Tobi.

I do not know any workaround but I try your code and I confirm that ruby  
imprint in memory grows very rapidly.  
I run the code on Ubuntu Intrepid.

Vincent.

---

<div class="post-metadata">

**Author:** ![Tobias\_LSSS\_tke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85e7bf/32.png) [@Tobias\_LSSS\_tke](https://www.ruby-forum.com/u/Tobias_LSSS_tke)\
**Post date:** [December 15, 2009, 10:54am UTC](https://www.ruby-forum.com/t/memory-leak-in-gdk-pixbuf-from-drawable/180167/3 "2009-12-15T10:54:16Z")

</div>

2009/12/14 Tobias LÃ¼tke [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Either i’m missing a way to tear down the images that come from a  
> Pixbuf.from\_drawable or ruby-gnome2 somehow keeps a permanent pointer  
> to the allocated image. The code below can fill up my 4gb of memory in  
> about 30 secs.

I think you are hitting this problem :  
[http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)

It is related to RMagick, but I think it also applies to GDK::Pixbuff.

> Gtk::timeout\_add(50) do  
> Â width, height = @window.size  
> Â window = @window.window

Gtk::timeout\_add(20000) do  
GC.start  
true  
end

> Â Gdk::Pixbuf.from\_drawable(window.colormap, window, 0, 0, width, height)
> 
> Â true  
> end
> 
> Gtk.main

btw, there is no Gdk.main\_quit, only Gtk, but it’s a typo I guess.

Get back to us if it helps.

Simon
