GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 22, 2014 3:34 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: consequeces of g_object_ref() ?
PostPosted: Mon Dec 14, 2009 7:29 am 
Offline
Familiar Face

Joined: Tue Jul 08, 2008 9:43 am
Posts: 8
I have a basic doubt about g_object_ref():

when do we need g_object_ref() ?
ie., in which all cases we want to increase reference count?

when we have a reference_count of 2 for a widget.
then if we destroy(say suppose gtk_widget_destroy() ) that widget
then ,will the reference count be 0 or 1 ?

please tell us pros & cons of g_object_ref() ? if possible please add p&c of g_object_unref() as well.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 14, 2009 12:29 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
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


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Tue Dec 15, 2009 4:03 pm 
Offline
Familiar Face

Joined: Tue Jul 08, 2008 9:43 am
Posts: 8
Thanks you very much ... i helped me a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group