Memory leak in Gdk::Pixbuf.from_drawable

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

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.

2009/12/14 Tobias Lütke [email protected]:

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

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