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