[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Attaching Data to Objects - when is destroy invoked



Hi,

I'm attaching data to a widget using gtk_object_set_data_full.  For example:

    gtk_object_set_data_full(widget,"ITEMS","Cool",destroy_me);

If I immediately destroy the widget, destroy_me doesn't get called.

It appears that I need to attach the widget to a container to have
destroy_me called, although that is just a guess at this point.

My feeling about how an 'object' should behave is that it should
call the destroy method of user attached data whenever the object
is destroyed.

I could use some educating about the rational behind this behaviour.

Demo code is attached below.  Help?

Kent


Here is a complete chunk of code that demonstrates the problem.
Change the value of ADD from 1 to 0 to see the oddity.

#include <stdio.h>
#include <gtk/gtk.h>

#define ADD 1

static void destroy_me(gpointer ptr) {
   fprintf(stderr,"destroy_me called :: ptr is '%s'\n",ptr);
}

int main(int argc, char *argv[]) {
   GtkWidget      *window,*label;

   gtk_init(&argc,&argv);

   window   = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   label    = gtk_label_new("Whoa");

   gtk_object_set_data_full(GTK_OBJECT(label),"ITEM","Cool",destroy_me);

   if (ADD) gtk_container_add(GTK_CONTAINER(window),label);

   fprintf(stderr,"Destroying label\n");
   gtk_widget_destroy(label);

   return(0);
}







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]