Re: GtkBuilder reference counting
- From: Murray Cumming <murrayc murrayc com>
- To: Johan Dahlin <jdahlin async com br>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: GtkBuilder reference counting
- Date: Tue, 26 Jun 2007 15:43:04 +0200
On Tue, 2007-06-26 at 10:39 -0300, Johan Dahlin wrote:
> 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.
I'd prefer it to be totally safe to unref and forget the GtkBuilder
object, and then continue to use the objects that it instantiated, as it
is currently possible with GladeXml. My previous mail suggested some
ways to allow this.
> [1]: http://bugzilla.gnome.org/show_bug.cgi?id=447967
--
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]