Re: newbie question about g_object unref()



On Fri, Nov 19, 2010 at 01:21:44PM +0000, N James Bridge wrote:
Thanks for all your contributions. I have now found G_IS_OBJECT(), which
is obviously the way to test whether the memory has been released or
not.

It obviously ISN'T.

If the memory was released then the argument is no longer a valid
GTypeInstance pointer as required (see the documentation).

If you want to nullify a pointer when you release your reference (which
I also find often useful as once you released your reference you may not
be longer sure the object exists at all) you should use a macro for
that, I use one defined approximately

    do { if (obj) { g_object_unref(obj); (obj) = NULL; } } while (0)

which, beside nullifying the pointer, is idempotent and can also be
freely used on NULL pointer.

Yeti




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