Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

[ruby-gtk2] Garbage collection and memory use
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

Report this thread to moderator Post Follow-up to this message
Old Post
David Espada
01-18-05 02:01 PM


Re: [ruby-gtk2] Garbage collection and memory use
Hi,

On Tue, 18 Jan 2005 18:01:10 +0900
David Espada <davinciSINSPAM@escomposlinux.org> wrote:

>  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.



Report this thread to moderator Post Follow-up to this message
Old Post
Masao Mutoh
01-18-05 09:09 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Ruby archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:14 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.