Re: Freeing memory allocated with gtk_*_new()
- From: sopwith redhat com (Elliot Lee)
- To: gtk-list redhat com
- Subject: Re: Freeing memory allocated with gtk_*_new()
- Date: 27 Jan 1999 19:24:40 GMT
On Wed, 27 Jan 1999 12:47:14 -0600 (CST), Sean Christopher Rhea
<srhea@ece.utexas.edu> wrote:
>What is the "proper" way to free memory allocated with gtk_*_new()?
>For instance:
>
>GtkWidget * foo = gtk_label_new ( "bar" );
>
>/* use foo */
>
>free ( foo ); /* this is wrong, right? */
>
>gtktypes.h declares gtk_type_free, but do I use that or is there some
>other (preferred) way to do it?
gtk_object_destroy(GTK_OBJECT(foo));
For widgets,
gtk_widget_destroy(GTK_WIDGET(foo));
will do almost exeactly the same thing, but hide the widget before
destroying it.
However, most of the time you do not have to free it up at all. When you
add the label into a container, for example, the container assumes
ownership of the label via a refcount, and the label is destroyed when the
container is destroyed.
I'm sure there's a good gtk+ tutorial out there somewhere,
-- Elliot
"In film you will find four basic story lines. Man versus man, man
versus nature, nature versus nature, and dog versus vampire."
- Steven Spielberg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]