Skip to content

GC is eating my widgets #105

@phil294

Description

@phil294

Hello,

consider this demo code which simply adds 100 buttons:

require "gobject/gtk/autorun"

window = Gtk::Window.new
window.connect "destroy", &->Gtk.main_quit
fixed = Gtk::Fixed.new
window.add fixed
50.times do |i|
    20.times do |j|
        btn = Gtk::Button.new label: i.to_s+"/"+j.to_s
        fixed.put btn, i*10, j*10
    end
end
window.show_all

Expected:
img
Actual:
img

Bug only appears with GC active (default).

In this case, GC starts killing off widgets every ~130 widget additions or so. This bug can also appear much faster, however. I am building AHK_X11, AutoHotkey for Linux, a scripting language. When I translate the above Crystal code into AHK, widgets are disappearing even after 3-20 widgets have been placed. I will add a demo code snippet + GIF below. Its internals aren't important I assume (because there is a lot of other stuff going on too in the background which probably affects GC behavior), I only want to show this to somewhat prove the severity of this bug: It definitely occurs with only a few buttons as well.

out-4

Same behavior with CheckButtons. Did not observe such behavior with ComboBoxes or Labels.

Did not investigate much further than all of this. I will gladly provide more input as needed, however. Any idea on how to at least circumvent this bug (other than -Dgc_none, of course) would be much appreciated, as this is kind of a blocker for me now.

On a related note, I am seeing a few different GLib null pointers (exceptions) and invalid memory access errors (process abort) then and again. For example, the above GIF window crashed (it always does at some point). Those appear seemlingly random, so I guess they are GC-related too, but I haven't tested this yet, and it's not a show stopper. I also cannot use malloc_pthread_shim because I am using -Dpreview_mt which does not seem to work together. Might need to open up new issue(s) at some point.

Thank you once again for all your work on this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions