Re: [gtk-list] Re: proper way to clean up



Federico Mena Quintero wrote:

> >  I have a structure that contains all my widgets:
> >
> >  typedef struct {
> >      GtkWidget *window;
> >      GtkWidget *vbox;
> >      GtkWidget *hbox;
> >      GtkWidget *label;
> >      GtkWidget *button;
> >  } Window;
>
> Normally you don't need pointers to all of the "auxiliary" widgets
> such as boxes and labels, but that's OK.

what would I do instead? Just have one generic widget that would be used for
all of them?
example:

typedef struct {
    GtkWidget *window;
    GtkWidget *widget;
} Window;

then use it like:

win->widget = gtk_label_new();
...
win->widget = gtk_button_new_with_label();
etc...

would this save memory that is malloc'd for this program?


>
>
> >  now the callback main_destroy_cb:
> >
> >  void main_destroy_cb(GtkWidget *widget, Window *win)
> >  {
> >      g_free(win);
> >      gtk_main_quit();
> >  }
> >
> >  Is this the proper way to malloc and free memory on exit for the Window
> >  structure?
>
> Yes.

Ok, here is my dilemma now:

is there a difference between the following g_malloc() calls

Window *win = g_malloc(sizeof(Window *));
Window *win = g_malloc(sizeof(Window));

if there is, should I use one over the other?

>
>
> >  Also, if the Window structure is not free'd, it would end up in a memory
> >  leak, correct?
>
> Yes.
>
>   Federico
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null

thanks again,
Aaron

--
Visit my web site at http://iconmedia.com/cgi-bin/index.pl

Current uptime:
 11:44am  up 13:41,  1 user,  load average: 0.34, 0.25, 0.18





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