Correct way to delete widgets? (Memleak)



Consider the following code:

#include <gtk/gtk.h>
int main(int argc, char **argv) {
  int i;
  GtkWidget * l;

  gtk_init(&argc,&argv);

  for (i=0; i<100000; i++) {
    l=gtk_label_new("Hello");
    gtk_object_unref((GtkObject *)l);
    l=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_object_destroy((GtkObject *)l);
  }

  exit(0);
}

This code compiles and runs succesfully, with no memory leaks.  However,
if I change the gtk_object_unref to gtk_object_destroy, I get a memory
leak, because the ref count never makes it to 0.  On the other hand, if
I change the gtk_object_destroy to gtk_object_unref, I get an assertion
error in gtk_object_unref because the reference count has dropped too
low.

I'm assuming this is a bug...it doesn't make sense to have to use
different deletion methods depending upon the widget you are dealing
with.  But which one is broken?

RedHat 5.2
Gtk

-- 
Richard Fish                      Enhanced Software Technologies, Inc.
Software Developer                4014 E Broadway Rd Suite 405
rjf@estinc.com                    Phoenix, AZ  85040 
(602) 470-1115                    http://www.estinc.com



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