Re: Memory Leak



Russell Strong <rstrong bigpond net au> writes:
>     object = gtk_object_new(gtk_object_get_type(),NULL);
>     gtk_object_destroy(object);

You need to do:

     object = gtk_object_new (gtk_object_get_type(), NULL);
     gtk_object_sink (object);

"destroy" merely broadcasts the message "everyone drop all their
reference counts," which for widgets typically means the parent
container of the object will drop its count, resulting in
finalization. For toplevel GtkWindow, GTK itself "owns" the window and
will drop a reference on destroy.

But in this case the only existing reference count is the floating
reference count, which no one owns. So no one is listening to remove
it.

The reason you need to gtk_object_sink () and not gtk_object_unref ()
is that you can only remove references from gtk_object_ref () with
gtk_object_unref (). The floating reference count must be removed with
gtk_object_sink ().

Havoc




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