Re: gobject reference question



Wallace Owen wrote:
How can I see what the current reference count is, so I can be sure I'm
using g_object_ref() and g_object_unref() correctly?

You can check G_OBJECT (object)->ref_count, note that it is
fundementally wrong to do any conditional code based on this
(for the same reason you cant check if any free'd memory is
actually free'd) but it may help you debug.

Also, there is a debugging mechanism built into GObject, I've
seen traces in the code suggesting that. You can set an object
to have its reference count watched (see gobject.c I guess to try
to work with that), otherwise, you might want to simply:

(gdb) watch ((GObject *)object)->ref_count

Many a time have I found myself trying to balance out these
references and finding my error (a typical error is to overlook
the incremented reference on an object obtained through
`g_object_get ("name", &object, NULL);' ).

Cheers,
                                 -Tristan



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