Re: GTK+ and memory allocation

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

 



On Sun, 28 Jun 2009 21:01:18 -0600
Michael Torrie <torriem@xxxxxxxxx> wrote:
> joshua.rh@xxxxxxxxxxx wrote:
> > GtkWidget *widget; 
> > 
> > widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); 
> 
> This is the way you have to do it.  As the function name implies, this
> allocates a new window.  If you want to get rid of it, you have to
> unref it which, when the ref count drops to zero, will cause it to be
> freed. If you don't you'll have a memory like.  This is pretty
> standard in C. Of course sometimes an API call gives you a pointer
> (reference to an object) but you don't need to free it when you're
> done because someone else will.

This is true as an overview of how it works, but you shouldn't call
g_object_unref() on a GtkWindow object to get rid of it.  You should
call gtk_object_destroy() or gtk_widget_destroy() on it, which will (by
emitting the destroy signal) cause amongst other things GTK+ to drop its
reference to the window. It will also cause GTK+ to do other clean-up,
such as taking it out of the list of top level windows.

Chris

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux