Re: GObject Destruction

On Mon, Dec 24, 2012 at 06:22:02PM -0200, Ian Liu Rodrigues wrote:
> I was wondering if this GObject destruction scheme allows destroying an
> object in a callback for a signal of itself.

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.

Subsequent handlers can be prevented from running with
g_signal_stop_emission() if necessary.

I hope this is sufficient.



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