Re: dynamic gtk_list_store
- From: John Coppens <john jcoppens com>
- To: Tim Müller <zen18864 zen co uk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: dynamic gtk_list_store
- Date: Mon, 14 Jun 2004 02:30:49 -0300
On Mon, 14 Jun 2004 00:32:14 +0100
Tim Müller <zen18864 zen co uk> wrote:
The store is a GObject and is freed/destroyed when its refcount reaches
zero. When you create a new list store with gtk_list_store_new(), it has
a refcount of 1. When you set the model on a GtkTreeView, the tree view
will add its own reference. So you basically need to do
store = gtk_tree_view_get_model (view);
gtk_tree_view_set_model (view, NULL);
g_object_unref (store);
Tim,
I've found the reference to 'unref'ing the liststore in the
'treeview_tutorial'. I suspect the third line to be unnecessary, as the
tutorial states:
[quote]
Tree models like GtkListStore and GtkTreeStore are
GObjects and have a reference count of 1 after creation. The tree view
will add its own reference to the model when you add the model with
gtk_tree_view_set_model, and will unref it again when you replace the
model with another model, unset the model by passing NULL as a model, or
when the tree view is destroyed. [1]
[end]
(At least if the store had a reference count of 1 at the time)
Still, I'm having trouble with the ref_count. GDB says:
(gdb) print *loglist.store
$25 = {parent = {g_type_instance = {g_class = 0x81f7330}, ref_count = 4,
qdata = 0x0}, stamp = -1791963214, root = 0x821d0e8, tail = 0x821d0e8,
sort_list = 0x8215e88, n_columns = 1, sort_column_id = -2,
order = GTK_SORT_ASCENDING, column_headers = 0x80e6720, length = 1,
default_sort_func = 0, default_sort_data = 0x0, default_sort_destroy =
0, columns_dirty = 1}
1) does this ref_count belong to the store, or to the parent?
2) somewhere, the ref_count gets incremented automatically. Is there some
other - indirect - action that increments the ref_count? I don't touch the
liststore anywhere after this:
gtk_tree_view_set_model(GTK_TREE_VIEW(logview),
GTK_TREE_MODEL(loglist.store));
g_object_unref(loglist.store);
At this point ref_count is 1 (as expected). If I interrupt the program in
gdb, I find that it went to 2.
John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]