I create an test_object which contains a function _finalize.
G_DECLARE_FINAL_TYPE(TestObject, test_object, TEST, OBJECT, GObject)
....
void test_object_finalize(GObject* object)
{
GObjectClass *parent = G_OBJECT_CLASS(test_object_parent_class);
TestObject *self = TEST_OBJECT(object);
g_free(self->name);
parent->finalize(object);
}
static void test_object_class_init(TestObjectClass* class)
{
GObjectClass *object_class = G_OBJECT_CLASS(class);
object_class->finalize = test_object_finalize;
}
If you create gtk_list_view only from g_list_model then everything works and when the program finishes, the _finalize function is called.
GtkSingleSelection* selection;
GtkListItemFactory* factory;
GListModel* model;
model = init_list();
factory = gtk_signal_list_item_factory_new();
selection = gtk_single_selection_new(G_LIST_MODEL(model));
listbox = gtk_list_view_new(GTK_SELECTION_MODEL(selection), factory);
But if you create gtk_list_view via gtk_tree_list_model then everything works, but when the program terminates, the _finalize function is not called and resources are not released.
GtkSingleSelection* selection;
GtkListItemFactory* factory;
GListModel* model;
GtkTreeListModel* treemodel;
model = init_list();
tree_model = gtk_tree_list_model_new(G_LIST_MODEL(model),FALSE,TRUE,get_child_model,NULL,NULL);
factory = gtk_signal_list_item_factory_new();
selection = gtk_single_selection_new(G_LIST_MODEL(tree_model));
listbox = gtk_list_view_new(GTK_SELECTION_MODEL(selection), factory);
What needs to be added so that the finalize function is called?