|
Hello.
You only rarely need to use g_object_ref() in your code. g_object_unref() is used a bit more, since data stores for tree view are normal objects and need to have initial reference removed when they are added to tree view in order to be destroyed properly, but apart from that, there is not much need for those two functions.
There is one situation where g_object_(un)ref() functions are handy is when updating large portion of tree view. In this case, it's useful to temporary remove data store from tree view, since this makes operation much faster. In this case you call g_object_ref() on data store just before removing it from tree view. This will make sure that store will survive the removal. After modifications are done and data store is again attached to tree view, you call g_object_unref() on store to restore reference count.
Playing with widget references is not recommended and usually not needed. Widgets will do the right thing in 99% of the cases if you simply leave them alone. And about your question on gtk_widget_destroy(), this function will only remove one reference, so if your widget has two references prior this call, it will not be destroyed when gtk_widget_destroy() is called. But again, if you leave widgets alone, they will do the right thing.
Tadej
|