Re: Reference Counting
- From: Matias Torres <torresmat gmail com>
- To: Nikhil Dinesh <nikhild seas upenn edu>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Reference Counting
- Date: Mon, 11 Sep 2006 20:26:56 -0300
ABOUT WEAK_REFERENCES
I can't get g_object_weak_ref working, this is the (full) example I've
tried it on. It tryes to free a GDate which is in a gtktreemodel.
/****************/
#include <gtk/gtk.h>
#include <glib.h>
#include <stdio.h>
void weak_ref (gpointer data, GObject *object) {
g_date_free (data);
printf ("weak_ref\n");
}
GtkTreeModel *generate_tree_model () {
GtkListStore *model;
GtkTreeIter iter;
GDate *date = g_date_new_dmy (10, 4, 1986);
model = gtk_list_store_new (
3,
G_TYPE_INT,
G_TYPE_STRING,
G_TYPE_POINTER,
-1);
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
0, 1,
1, "Holaaaa",
2, date, -1);
g_object_weak_ref (G_OBJECT(model), (GWeakNotify) weak_ref, date);
date = g_date_new_dmy (10, 4, 1986);
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
0, 2,
1, "Chauuu",
2, date, -1);
g_object_weak_ref (G_OBJECT(model), (GWeakNotify) weak_ref, date);
return GTK_TREE_MODEL (model);
}
GtkWidget *generate_tree_view () {
GtkTreeView *treeview;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
treeview = GTK_TREE_VIEW (gtk_tree_view_new ());
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("UNO",
renderer, "text", 0, NULL);
gtk_tree_view_append_column (treeview, column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("DOS",
renderer, "text", 1, NULL);
gtk_tree_view_append_column (treeview, column);
return GTK_WIDGET (treeview);
}
int main (int argc, char **argv) {
GtkWidget *window;
GtkWidget *treeview;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Reference Counting");
treeview = generate_tree_view ();
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview),
generate_tree_model ());
gtk_container_add (GTK_CONTAINER (window), treeview);
g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK
(gtk_main_quit), NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
It NEVER prints "weak ref".
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]