Forum: Ruby-Gnome 2 Memory leak in Gdk::Pixbuf.from_drawable

Posted by Tobias Lütke (Guest)
on 2009-12-14 00:36
(Received via mailing list)
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
Posted by Vincent Carmona (vinc-mai)
on 2009-12-15 09:38
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.
Posted by Simon Arnaud (Guest)
on 2009-12-15 10:54
(Received via mailing list)
2009/12/14 Tobias Lütke <tobi@leetsoft.com>:
> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.