GtkBuilder reference counting
- From: Johan Dahlin <jdahlin async com br>
- To: Murray Cumming <murrayc murrayc com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: GtkBuilder reference counting
- Date: Tue, 26 Jun 2007 10:39:53 -0300
Murray Cumming wrote:
[..]
> I also think that the memory management of the result of
> gtk_builder_get_object() should be made clearer. It was never very clear
> for glade_xml_get_widget(), but it's more complicated now that we can
> get objects as well as widgets.
>
> For widgets, I guess that it's like this:
> 1. For child widgets, such as GtkButton, they belong to their parent
> containers and will be destroyed by them when the containers are
> destroyed, so you don't need to call g_object_unref() or
> gtk_widget_destroy().
> 2. For top-level windows, such as GtkWindow, they should be destroyed
> with gtk_widget_destroy() when you are finished with them.
>
> But for objects, I guess that:
> 3. For objects, such as GtkTreeModel, g_object_unref() should be called.
> This would require that a reference is given when
> glade_xml_get_widget() is called a second time, as well as the first
> time. This would be inconsistent with other GTK+ API, but it does not
> seem sensible to expect the application code to know when the result has
> just been instantiated rather than simply returned again.
>
>
> And it would be nice to know whether the objects are reference/owned at
> all by the GtkBuilder instance? For instance, should we expect the
> widgets to be destroyed when the GtkBuilder instance is unreferenced? I
> guess not, but it should be stated.
The reason it's not documented or even stated is that it's currently not
defined. The last major GtkBuilder task that needs to be finished before
2.12 is the reference counting bug[1].
I could use some help to design the behavior of objects created by the
GtkBuilder, I'm not an expert in the area, I spend most of my time
in languages where I don't really have to care.
I'd like to make these use cases possible:
* Construct a builder, fetch a window, unref the builder
This should free all the resources allocated by the builder and all
objects not used to construct the window, including all children.
gtk_widget_destroy(window) should later free all the resources, including
GObjects such as GtkUIManager, GtkTreeModel.
If you want to reuse objects such as treemodels for other purposes outside
of the GtkBuilder hierarchy you'd have to fetch the object before unreffing
the builder.
[1]: http://bugzilla.gnome.org/show_bug.cgi?id=447967
--
Johan Dahlin <jdahlin async com br>
Async Open Source
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]