[Gtk-sharp-list] GLib Timeout and garbage collection clarification

Nicholas Frechette zeno490 at gmail.com
Sun Feb 20 09:57:25 EST 2011


Hi,
Looking at GLib.Timeout, there is only an Add function, no remove/delete.

If I have a gui element that creates a timeout to be called repeatedly at an
interval and eventually that widget is garbage collected, what happens to
the timeout handler? Will it still be called? Is there a guard internally
for this?

ie in pseudo code:
class Foo : Widget
{
  public Foo() : base()
  {
    GLib.Timeout.Add(1000, Bar);
  }

  private bool Bar()
  {
    SomeLabel.Text = DateTime.Now.ToString(); // Is this always safe?
SomeLabel might have been GCed if "this" has been GCed as well?
    return true; // ???
  }
}

Should I override dispose, set a flag that is checked in the handler and
return false then? Is that safe? Will the object still be "live" when the
handler next attempts to fire? Is the GTK underlying system smart enough to
detect that the handler's source has been GCed and thus should be removed
automatically?

The documentation is very silent about this.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110220/293560c3/attachment.html 


More information about the Gtk-sharp-list mailing list