gtk+-1.2 dynamic widget create/destroy reference beancounting



p = gtk_<some_widget>_new () ;
gtk_widget_ref (p) ;
gtk_object_set_data_full (GTK_OBJECT (the_dialog_box), "p", p,
  (GtkDestroyNotify) gtk_widget_unref) ;
gtk_widget_show (p) ;
gtk_container_add (some_container, p) ;
gtk_signal_connect (p, "clicked", some_sig_handler, NULL) ;

/* Dialog box is shown, then hidden.  Next time, before it's shown again
*/

gtk_signal_disconnect_by_func (p, some_sig_hander, NULL) ;
gtk_container_remove (some_container, p) ;
gtk_object_remove_data (GTK_OBJECT (the_dialog_box), "p") ;
gtk_widget_destroy (p) ;

gtk_widget_destroy, at this point gices me a critical error saying p
fails the GTK_IS_WIDGET () assertion.  The way I lined up the
destruction code (above, after the comment about the dialog box) is such
that gtk_widget_destroy lines up with gtk_widget_new:

gtk_widget_new <-> gtk_widget_destroy
gtk_widget_ref <-> gtk_object_remove_data (calls gtk_widget_unref)
gtk_container_add <-> gtk_container_remove
gtk_signal_connect <-> gtk_signal_disconnect

I'm assuming gtk_widget_show does not increment the widget's reference
count.  I am also assuming that gtk_widget_new *MUST* be countered by
gtk_widget_destroy.  However, given the critical error I receive due to
the failed assertion, it seems like I no longer need to call
gtk_widget_destroy.  Is this really the case ? I want to make sure I
don't have any "widget leaks" in my code.



TIA




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