Search code examples
glibgobjectrefcounting

Do i need to do g_object_unref() on glib signal parameters?


when i connect a signal to a callback function the callback functions gets passed parameters. Is the reference counter increased before the objects get passed to my callback function or do i have to increase it by myself.

I guess there must be some sort of convention for that because nothing like that is mentioned in the documentation of gtk or libgobject.


Solution

  • Generally, you do not assume a reference on an object when it is passed to your callback. You only assume a reference when the object is the return value of a method which is annotated with "transfer full". You can see these annotations in the documentation.

    (I say "generally" because there may always be badly constructed libraries whose API violates these guidelines. You can't do a whole lot about that, though.)