Re: Reference counting
- From: Alwin Leerling <leerling xtra co nz>
- To: tristan van berkom gmail com
- Cc: gtk-list <gtk-list gnome org>
- Subject: Re: Reference counting
- Date: Sun, 23 Dec 2007 17:21:22 +1300
Tristan Van Berkom wrote:
On Dec 23, 2007 1:20 AM, Alwin Leerling <leerling xtra co nz
<mailto:leerling xtra co nz>> wrote:
Hi,
I'm slightly overwhelmed as to the whole reference counting issue.
Could
someone explain the though process or logic behind the reference
counting or direct me to some information where I can find the
correct
use. For example, in my code I set up my combo boxes on startup using
gtk_list_store_newv and gtk_combo_box_set_model. (Do I need to
unref the
list_store pointer at this stage?)
This is a question of how you interpret your application, think, do you
want to give the ownership of your data model to your view widget ?
This application is purely the gui part of my system. I have another
application that does the actual work, so my gui is totally stateless.
To my knowledge is it advantageous to give the ownership to the view
widget as I don't have to keep variables laying around. If I need
something like the store I can always request it from GTK.
Will you be having multiple list stores that you might want to keep
around and alternate the view ?
No, I initialise the stores on startup and just add/remove items from them.
If you unref your list store (passing ownership to the combo box), then
destroying (freeing) the combo box will take care of finalizing (freeing)
the list store.
Does this mean that I have to unref the store as soon as I have assigned
it to the combo (gtk_combo_box_set_model) ?
At a later stage I am ready to put
some data in the combo box, so I get the store (with
gtk_combo_box_get_model) and add some entries to the sore. Do I
need to
unref the aquired pointer?
No. in general gtk_[widget]_get_[parameter]() functions never duplicate
strings or add references (strings are easier because they are always
const return values if they are not duplicated).
Usually a returned value that has a reference will note in the docs that
it must be unreffed (strings from g_object_get() are dupped and objects
refcount incremented for instance).
To make matters more confusing, I also have a
couple of combo's with filters. I wrote a little stub to acquire
the store:
GtkTreeModel * gtk_combo_get_filter_model( GktComboBox * combo )
{
return gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER(
gtk_combo_box_get_model( combo ) ) );
}
Do I leak a reference here?
No.
Also read the description portion of:
http://library.gnome.org/devel/gtk/unstable/GtkObject.html
I read that but it was not clear to me which GTK calls add references
and which are not. In my code I never add a reference explicitly but I
have no idea what the GTK library does. I am heartened by your comment
that if a GTK library call adds a reference, it is noted in the
documentation.
Cheers,
-Tristan
Thanks for your help.
Alwin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]