Re: GObject Destruction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for the late response, the email got lost in my messy inbox.

On Mon, Dec 24, 2012 at 7:20 PM, David Nečas <yeti@xxxxxxxxxxxxxxx> wrote:
> Yes and no.  You can do this

>     g_signal_connect(object, "signal", G_CALLBACK(g_object_unref), NULL);

> and it will unref the object when the signal is emitted.  However, an
> object cannot just go poof! during the signal emission (so, no
> destruction *in* the callback).  Before the actual emission starts a
> reference is taken within GLib; after it is done the reference is
> released.  A signal handler such as above can thus cause that at this
> moment, i.e. after all handlers are run, the reference count drops to
> zero and the object is destroyed.

I chatted a little with the developers at #gtk+, and they stated that the gtk widgets are indeed destroyed in a signal callback. For instance, the GtkWindow is usually destroyed in the "delete-event" signal.

Is there a rule of thumb when emitting signals to avoid this problem? How does gtk allow destruction inside their own signals?

My application is handling socket connections with classes that we made before GIO implemented their own GSocket, and now we are experiencing some problems like this. We usually don't know when to unref the object unless in their own signal handlers.

The only rule I can think of is that you shouldn't do absolutely anything after a signal emission that might destroy your object.

Regards,
Ian L.
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux