Thanks Yu, Now I could understand a little bit about floating and reference count. :-)
I'm sorry to bother you, but.. then are the following answers right? 1. If I use GtkCellRenderSpin and make new GtkAdjustment which is saved in the **Renderer**, then do I have to do g_object_unref(adj) ? -> DO NOT g_object_unref() since GtkCellRenderSpin will eliminates floating and it will free GtkAdjustment. 2. If I use GtkCellRenderSpin and make new GtkAdjustment which is saved in the **GtkTreeModel** with setting attribute, then do I have to do g_object_unref(adj) ? -> DO g_object_ref() 3. If I use GtkCellRenderCombo and make new Gtk{Tree|List}Store which is saved in the **Renderer**, then do I have to do g_object_unref(model) ? -> DO g_object_ref_sink() then g_object_ref() <-- Is this right? 4. If I use GtkCellRenderCombo and make new Gtk{Tree|List}Store which is saved in the **GtkTreeModel** with setting attribute, then do I have to do g_object_unref(model) ? -> DO g_object_ref() Thanks again, :-) 2008/12/12 Yu Feng <rainwood...@gmail.com> > Hi Kim, > > Usually if a property of a GObject is G_TYPE_OBJECT, the GObject will > hold a reference count of that property. > > And because your GtkAdjustment is created in a floating state, you don't > need to unref it after setting it as a property value of a GObject. > > refer to line 209:gtkcellrendererspin.c > if (obj) > priv->adjustment = g_object_ref_sink (obj); > break; > > and line 150:gtkcellrendererspin.c > if (priv && priv->adjustment) > g_object_unref (priv->adjustment); > > > > adj = GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 100.0, 5.0, > > 10.0, 0.0)); > > adj->ref_count = unknown, > adj->is_floating = true. > > renderer = gtk_cell_renderer_spin_new (); > renderer->ref_count = unknown > renderer->is_floating = true > > > > > > g_object_set (renderer, "editable", TRUE, "adjustment", adj, > > "digits", 0, NULL); > > > > renderer->ref_count = unknown > renderer->is_floating = true > adj->ref_count = 1 > adj->is_floating = -1 > > > the remaining ref_count of adj shouldn't be freed by you. It will be > freed in GObjectClass->dispose of renderer. (that's why that reference > is owned by renderer: who frees, who owns) > > Yu > > On Fri, 2008-12-12 at 14:10 +0900, Keedi Kim wrote: > > HI, :-) > > > > Memory leak and reference counts are very confused. > > I am using GtkTreeView with GtkCellRendererCombo and GtkCellRenderSpin. > > So, I use Adjustment for GtkCellRendererSpin > > and GtkListStore(or GtkTreeStore) for GtkCellRenderCombo. > > > > Some of columns uses same Adj, and TreeModel, so saved them in renderer. > > Rest of columns uses different so I saved them in GtkTreeModel and set > > attributes. > > > > Anyway, I'm very confusing about memory management. > > > > I have understood I have to decrease reference count to avoid memory leak > > when I use following API because they increase reference count: > > > > g_object_set() > > gtk_tree_store_set() > > > > Now I have some question about those API, and > GtkCellRenderer{Combo|Spin}. > > > > 1. > > If I use GtkCellRenderSpin and make new GtkAdjustment > > which is saved in the **Renderer**, then do I have to do > g_object_unref(adj) > > ? > > > > 2. > > If I use GtkCellRenderSpin and make new GtkAdjustment > > which is saved in the **GtkTreeModel** with setting attribute, > > then do I have to do g_object_unref(adj) ? > > > > 3. > > If I use GtkCellRenderCombo and make new Gtk{Tree|List}Store > > which is saved in the **Renderer**, then do I have to do > > g_object_unref(model) ? > > > > 4. > > If I use GtkCellRenderCombo and make new Gtk{Tree|List}Store > > which is saved in the **GtkTreeModel** with setting attribute, > > then do I have to do g_object_unref(adj) ? > > > > 5. > > Is there any connection with floating issues? > > When I save GtkAdjustment in Renderer > > before saving, floating value is true > > and after saving floating value is false, > > But I save GtkAdjustment in GtkTreeModel, > > before saving, and after saving floating value is still true. > > > > And here is some code snippets for asking this issues. > > > > * code snippet which saves GtkAdjustment in Renderer > > code: > > > { > > > GtkAdjustment *adj; > > > GtkCellRenderer *renderer; > > > GtkTreeViewColumn *column; > > > > > > adj = GTK_ADJUSTMENT (gtk_adjustment_new (50.0, 0.0, 100.0, 5.0, > > 10.0, 0.0)); > > > renderer = gtk_cell_renderer_spin_new (); > > > > > > { > > > gboolean colorness_float; > > > colorness_float = g_object_is_floating (adj); > > > g_debug ("=========> float: colorness(%d)\n", > colorness_float); > > > } > > > > > > g_object_set (renderer, "editable", TRUE, "adjustment", adj, > > "digits", 0, NULL); > > > > > > { > > > gboolean colorness_float; > > > colorness_float = g_object_is_floating (adj); > > > g_debug ("=========> float: colorness(%d)\n", > colorness_float); > > > } > > > > > > g_object_unref (adj); <----- /* DO I NEED THIS? */ > > > > > > g_signal_connect (G_OBJECT (renderer), "edited", G_CALLBACK > > (brightness_edited), window); > > > > > > column = gtk_tree_view_column_new_with_attributes > > (_(column_titles[VIEW_CAMERA_BRIGHTNESS]), > > > renderer, > > > "text", > > MODEL_CAMERA_BRIGHTNESS, > > > "visible", > > MODEL_SUPPORT_CAMERA_PROPERTY, > > > "sensitive", > > MODEL_ONLINE, > > > NULL); > > > gtk_tree_view_column_set_resizable (column, FALSE); > > > gtk_tree_view_column_set_clickable (column, FALSE); > > > gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); > > > } > > > > result: > > > =========> float: colorness(1) > > > =========> float: colorness(0) > > > > * code snippet which saves GtkAdjustment and GtkListStore in > GtkTreeModel. > > code: > > > { > > > GtkAdjustment *bitrate_adj, *gop_size_adj; > > > GtkListStore *quality_model; > > > gchar quality_str[1024]; > > > > > > bitrate_adj = GTK_ADJUSTMENT (gtk_adjustment_new (10.0, 10.0, > 100.0, > > 10.0, 20.0, 0.0)); > > > gop_size_adj = GTK_ADJUSTMENT (gtk_adjustment_new (10.0, 10.0, > > 100.0, 10.0, 20.0, 0.0)); > > > > > > quality_model = gtk_list_store_new (2, G_TYPE_STRING, > G_TYPE_INT); > > > { > > > GtkTreeIter combo_iter; > > > gchar str[1024]; > > > gint value; > > > > > > value = 1; > > > g_snprintf (str, 1024, _("%d (Highest)"), value); > > > g_strlcpy (quality_str, str, 1024); > > > gtk_list_store_append (quality_model, &combo_iter); > > > gtk_list_store_set (quality_model, &combo_iter, 0, str, 1, > > value, -1); > > > > > > value = 2; > > > g_snprintf (str, 1024, "%d", value); > > > gtk_list_store_append (quality_model, &combo_iter); > > > gtk_list_store_set (quality_model, &combo_iter, 0, str, 1, > > value, -1); > > > > > > value = 3; > > > g_snprintf (str, 1024, _("%d (Lowest)"), value); > > > gtk_list_store_append (quality_model, &combo_iter); > > > gtk_list_store_set (quality_model, &combo_iter, 0, str, 1, > > value, -1); > > > } > > > > > > { > > > gboolean bitrate_float, gop_size_float, quality_float; > > > > > > bitrate_float = g_object_is_floating (bitrate_adj); > > > gop_size_float = g_object_is_floating (gop_size_adj); > > > quality_float = g_object_is_floating (quality_model); > > > > > > g_debug ("=========> float: bitrate(%d), gop_size(%d), > > quality(%d)\n", bitrate_float, gop_size_float, quality_float); > > > } > > > > > > g_object_ref_sink (bitrate_adj); > > > g_object_ref_sink (gop_size_adj); > > > > > > gtk_tree_store_set (GTK_TREE_STORE (model), iter, > > > MODEL_VIDEO_FRAME_RATE, 1, > > > MODEL_VIDEO_BITRATE, 10, > > > MODEL_VIDEO_GOP_SIZE, 10, > > > MODEL_VIDEO_QUALITY, 1, > > > MODEL_VIDEO_QUALITY_STRING, quality_str, > > > MODEL_VIDEO_BITRATE_ADJ, bitrate_adj, > > > MODEL_VIDEO_GOP_SIZE_ADJ, gop_size_adj, > > > MODEL_VIDEO_QUALITY_MODEL, quality_model, > > > -1); > > > { > > > gboolean bitrate_float, gop_size_float, quality_float; > > > > > > bitrate_float = g_object_is_floating (bitrate_adj); > > > gop_size_float = g_object_is_floating (gop_size_adj); > > > quality_float = g_object_is_floating (quality_model); > > > > > > g_debug ("=========> float: bitrate(%d), gop_size(%d), > > quality(%d)\n", bitrate_float, gop_size_float, quality_float); > > > } > > > > > > g_object_unref (bitrate_adj); <----- /* DO I NEED THIS? */ > > > g_object_unref (gop_size_adj); <----- /* DO I NEED THIS? */ > > > g_object_unref (quality_model); <----- /* DO I NEED THIS? */ > > > } > > > > result: > > > =========> float: bitrate(1), gop_size(1), quality(0) > > > =========> float: bitrate(0), gop_size(0), quality(0) > > > > > > Any suggestions and help will be appreciated. > > Thanks, :-) > > > > P.S. > > If there are documentations for this issues. > > Could you please recommand the url please? > > > > -- Best regards, Keedi Kim _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list