Re: gtk_widget_ref() /gtk_widget_unref() ?
- From: Tristan Van Berkom <vantr touchtunes com>
- To: Fabio Zanetta <znt fabio virgilio it>
- Cc: "GTK2.0" <gtk-app-devel-list gnome org>
- Subject: Re: gtk_widget_ref() /gtk_widget_unref() ?
- Date: Tue, 12 Nov 2002 15:15:54 -0500
Can someone tell me the aim of gtk_widget_ref/gtk_widget_unref?
g_object_ref/g_object_unref
are methods of the GObjectClass.
I'm not sure about the implementation history
of gtk_widget_ref/unref but I think they were either
wrappers to G_OBJECT(widget)->ref/unref or a seperate
reference count implemented at the GtkWidget level when
GtkWidget was derived from GtkObject. (still is but
GtkObject now is derived from GObject which already
implemets ref/unref etc...).
So in short the GObject is now the base class of
all widgets and the reference count is stored in
the GObject level.
In online docs (in docs downloaded they are ok...) are signed as deprecated
in favour of g_widget_ref/g_widget_unref, but they don't say what is their
use.
when creating an object; your object has a reference
count of 1. if you add your object to a container;
your container will "hold a reference" on that object
(call g_object_ref) untill the container is destroyed or
the object is removed from the container.
If you create an object and add it to a container and
than call g_object_unref on the object; the container
"owns" the object and you dont have the right to depend on
its existance (seeing as you dont "hold a reference" on it
anymore).
When a reference count falls to 0 the object is
finalized (the resources are freed).
The correct way to destroy widgets you dont need
is to call g_object_unref(G_OBJECT(widget));
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]