Re: Release memory for a GtkWindow



On Thu, Mar 14, 2002 at 09:46:56AM +0100, zze-coframi balr001 wrote:
Hello,

here again a quaestion about memory freeing for GtkWindow objects.
I create my window like this 

GtkWidget * create_window (void){
      GtkWidget * window = gtk_window_new (WINDOW_TOP_LEVEL);
      .......
      
      GtkButton * button = gtk_button_new ();
      ....
      gtk_widget_set_name (button, "button");
      gtk_widget_ref (button);
      gtk_widget_show (button);
      gtk_object_set_data_full (GTK_OBJECT (window), "button", button,
(GtkDestroyNotify) gtk_widget_unref);
      gtk_container_add (GTK_CONTAINER (window), button);

      .........
      return window;
}


int main (){
      GtkWidget * toto = create_window ();

      return;
}


To destroy my window toto, do I only need to call gtk_object_destroy
(GTK_OBJECT (toto)); or do I need to call gtk_widget_unref (button) and
after call  gtk_object_destroy on the window ??

Thanks a lot for answers !

Isabelle

---end quoted text---
In this case would be better you call 2 times gtk_widget_unref(window)
becose when you create it, it has ref count at 1, you referenced it, so it's
at 2, and then you wanna delete, so 2 - 1 = 1   1 - 1 = 0, it's 2 times you
have to call, becose you didn't release the reference of the builder function.
If you relay on references, would be easier to you keep in mind the count for
that..
Many people to avoid widget destruction by another thread, do this:
gtkentry *e;
gtk_widget_ref(e);
gtk_entry_get_text(e);
gtk_widget_unref(e);
/* just an example */
so the counters would always be at level 1, and when you wanna free it, just
unref more one time (this can be undestood as a closing-bracket for the widget
creation..)

[]'s
-- 
Marcelo R Leitner <mrl netbank com br>
ICQ #: 29966851



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