Garbage Collection causes segfaults

Hi. I’m having a problem with a Ruby-Gnome2 application I’ve been
building. For some reason my program randomly segfaults. I fixed this
by disabling garbage collection(Maybe GC was cleaning up gnome objects
that were still in use?) but of course now my application runs out of
memory relatively quickly (not so much from the gtk objects, but from my
non-gnome objects that are memory hogs that need garbage collection).

I was wondering if there is any known reasons that the garbage
collection might cause problems with ruby-gnome2, and if there are any
workarounds I might employ to avoid them besides disabling my garbage
collection?

Any ideas would be appreciated

Conan

On Wed, Jun 13, 2007 at 07:46:55PM +0200, Conan wrote:

I was wondering if there is any known reasons that the garbage
collection might cause problems with ruby-gnome2, and if there are any
workarounds I might employ to avoid them besides disabling my garbage
collection?

I guess you’re still using Ruby-Gnome2 version 0.15, which had lots of
errors
related to memory management. You should upgrade to 0.16.

FYI, you can also manually run garbage collection with GC.start.

Cheers,
Markus


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

Markus K. wrote:

I guess you’re still using Ruby-Gnome2 version 0.15, which had lots of
errors
related to memory management. You should upgrade to 0.16.

FYI, you can also manually run garbage collection with GC.start.

I’m using the ruby-gnome2-0.16.0-1-i386-mswin32.exe installer, so that
should be ok?.

GC.start won’t run while GC is disabled(and when it is enabled, it’ll
occasionally cause an segfault which seems to be my problem)

Ok, hopefully this code comes out unmangled…

To trigger a segfault, just run this code and click furiously on the
listbox. After a while(10 seconds of furious mouse clicking) it’ll
segfault on my computer. I’m running ruby 1.8.2 on a windows 32 bit
machine with ruby-gnome2-0.16.0-1(Windows installer)

#Contrived example to get a segfault bug
require ‘gtk2’

#Fill up the list box
def fill_box(model)
[‘Stuff’,‘More Stuff’,‘Cool Stuff’,‘Lame stuff’].each do |l|
iter = model.append
iter[0] = l
end
end

window = Gtk::Window.new
label_model = Gtk::ListStore.new(String)
label_box = Gtk::TreeView.new(label_model)

t_render = Gtk::CellRendererText.new
label_box.append_column(Gtk::TreeViewColumn.new(“Sample Set”, t_render,
:text => 0))
window.add(label_box)
fill_box(label_model)

label_box.signal_connect(“cursor-changed”) do |treeview|
0.upto(100) do |iii| #More chances to generate a bug
current_label = treeview.selection.selected
current_label = current_label[0] if(current_label != nil)
label_model.clear

fill_box(label_model)

end
end

window.show_all
Gtk.main

Hmm, maybe thats the case then. I’ll give it a shot and see what
happens. (Also, try changing the 100 to 1000 or 10000, that reduces the
number of furious clicks needed)

Daniel L. wrote:

After about a minute of clicking as fast as I possibly could, I started
to consider the possibility that you were having a little fun with me.
:slight_smile:

Sorry, no segfaulting. Have you tried running with Ruby 1.8.6? I have
used another C extension that segfaulted until I upgraded.

best,
Dan

Conan R. wrote:

label_box = Gtk::TreeView.new(label_model)
current_label = current_label[0] if(current_label != nil)
label_model.clear

fill_box(label_model)

end
end

window.show_all
Gtk.main

Yeah, your right. Upgrading to Ruby 1.8.6 seems to have solved the
problems. Great, thanks for your help!

Conan R. wrote:

Hmm, maybe thats the case then. I’ll give it a shot and see what
happens. (Also, try changing the 100 to 1000 or 10000, that reduces the
number of furious clicks needed)

After about a minute of clicking as fast as I possibly could, I started
to consider the possibility that you were having a little fun with me.
:slight_smile:

Sorry, no segfaulting. Have you tried running with Ruby 1.8.6? I have
used another C extension that segfaulted until I upgraded.

best,
Dan

Conan R. wrote:

label_box = Gtk::TreeView.new(label_model)
current_label = current_label[0] if(current_label != nil)
label_model.clear

fill_box(label_model)

end
end

window.show_all
Gtk.main


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

Hi,

If you’ll have segfaults problem again, require the code below
before executing your apps.

gctest.rb

Thread.new do
loop do
sleep 0.01
GC.start
p “GCed”
end
end

Then,

$ ruby -rgctest yourapp.rb

You are able to get the segfaults faster.

On Thu, 14 Jun 2007 18:40:46 +0200
Conan R. [email protected] wrote:

Posted via http://www.ruby-forum.com/.


This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/