[ruby-gtk2] Garbage collection and memory use

D

David Espada

Hi all.

Look at next script:

----------------------------------------
#!/usr/bin/ruby

require 'glib2'
require 'gtk2'

def bucle
1000.times do |i|
100.times do |j|
p i
p j
p '******'
v = Gtk::Window.new.show_all
v.destroy
end
GC.start
end
end

Gtk::init

ventana = Gtk::Window.new
ventana.set_title("Creating windows")
ventana.signal_connect('delete_event') {exit}


vbox = Gtk::VBox::new(true, 10)

boton = Gtk::Button.new('_start', true)
boton.signal_connect('clicked') do bucle end
vbox.pack_start(boton, true, true, 0)

ventana.add(vbox)

ventana.show_all

Gtk.main
--------------------------------------------

When you push button, it triggers a loop that creates and destroy a
Gtk2 window in each iteration. For each 1000 iters, I call GC.start in
order to run Garbage Collection.

In theory, there is no single variable that persist from one iter to
next, and garbage collection should reget memory for more use, without
collapsing physical memory and swap space.

But that is what happens actually, and I don't know the reason.

You can say that this lanscape is very rare and not reproducible in
practice, but I have an application that creates and destroys windows
with many widgets, and it loads system until swaping is constant,
slowing work of my users.

What is problem with Garbage Collection? Why it doesn't free memory
althought I invoque it explicitly? Any clue or solution that doesn't
force me to change all code in order to reuse windows instead of
create them when I need?

I am in the very edge, but it seems that Ruby Garbage Collection
doesn't work properly with Gtk2 widgets, because memory is not freed.

Thanks for your ideas and help.

I use last version of Ruby (1.8.2) with last version of Ruby-gtk2
(0.11.0) in Linux Debian Sid, with kernel 2.6.7.

Greets.

David
 
M

Masao Mutoh

Hi,

Hi all.

Look at next script:
When you push button, it triggers a loop that creates and destroy a
Gtk2 window in each iteration. For each 1000 iters, I call GC.start in
order to run Garbage Collection.

In theory, there is no single variable that persist from one iter to
next, and garbage collection should reget memory for more use, without
collapsing physical memory and swap space.

But that is what happens actually, and I don't know the reason.
What is problem with Garbage Collection? Why it doesn't free memory
althought I invoque it explicitly? Any clue or solution that doesn't
force me to change all code in order to reuse windows instead of
create them when I need?


Try the code below:
(gcc -o test `pkg-config gtk+-2.0 --libs --cflags` test.c)
---
#include <gtk/gtk.h>

int main(int argc, char** argv){
GtkWidget* window;
gtk_init(&argc, &argv);

while(TRUE){
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show_all(window);
gtk_object_destroy(GTK_OBJECT(window));
}
gtk_main();
return 0;
}
---

You can notice it does not concern Ruby GC.
I'm not sure but gtk_widget_show_all() causes this problem.
I am in the very edge, but it seems that Ruby Garbage Collection
doesn't work properly with Gtk2 widgets, because memory is not freed.

Any solutions?

P.S.
I don't think it's not good idea to post these discussions here.
If you want to discuss more, come ruby-gnome2 ML again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top