Re: GtkBuilder memory management
- From: Krzesimir Nowak <qdlacz gmail com>
- To: Bastien Dalla Piazza <bastien dallapiazza gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: GtkBuilder memory management
- Date: Mon, 15 Feb 2010 00:05:01 +0100
On Sun, 2010-02-14 at 10:59 +0100, Bastien Dalla Piazza wrote:
> Hi,
>
> I've been wondering about the memory management of GtkBuilder and did
> not find an answer in the documentation:
>
> When using a derived widget: GtkBuilder::get_widget_derived(...), one
> retrieves a pointer on a widget. Is the user responsible to free
> (delete) the pointer or is this handled when the GtkBuilder is itself
> destroyed?
If get_widget_derived() is used to retrieve a toplevel widget (Window,
Dialog, Assistant, etc) you have to delete it. When using
Gtk::Builder::get_widget_derived() on non-toplevel widget or
Gtk::Builder::get_widget() on any widget then no deleting is needed.
Also when a widget is retrieved with Gtk::Builder::get_widget_derived()
e.g. two times, you should call delete only once:
MyWidget* my_widget = 0;
MyWidget* my_widget_again = 0;
builder->get_widget_derived("my_widget", my_widget);
builder->get_widget_derived("my_widget", my_widget_again);
delete my_widget;
my_widget = 0;
// don't do double delete.
my_widget_again = 0;
>
> For instance, if a glade file contains, say, several derived dialogs:
> when loading the *.glade file, are all the widgets created or are they
> created only when the user wants a pointer/reference to them?
>
Well, there is no such notion like 'derived widget' in glade file itself
- this exists only in your code. And widget creation depends on method
you use:
`Gtk::Builder::create_from_file(const std::string& filename)'
instatiates all widgets in given glade file, but when
`Gtk::Builder::create_from_file(const std::string& filename, const char*
id)' is used then builder instatiates a widget with given id and all its
children.
But using the former does not mean that you have to explicitly free all
toplevel widgets - see answer for your first question above.
> Cheers!
Hope that helps (and hope that I'm right :P),
Krzesimir
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]