Fwd: Problem with memory management with builder.
- From: Krzysztof Łochwinowicz <krzysztof lochwinowicz gmail com>
- To: kjell ahlstedt bredband net
- Cc: gtkmm-list gnome org
- Subject: Fwd: Problem with memory management with builder.
- Date: Tue, 21 Jun 2011 01:31:12 +0200
Hi Krzysztof,
I'm only 99% sure of this, but here's how I think it works:
When a top-level window (or any container) is deleted, its child widgets
are not unconditionally deleted. They are unreferenced, i.e. their
reference counts are decreased by 1, and only if a widget's ref count
reaches 0, the widget is deleted.
Now Gtk::Builder::get_widget(), as opposed to gtk_builder_get_object(),
increments the ref count of the fetched widget. (This is 100% sure.)
When you delete the window containing the button, the button is not
deleted, because "refBuilder->get_widget("button1", button);" has
increased the ref count of button1. When window1 is deleted, the
button's ref count decreases from 2 to 1, not from 1 to 0.
If you want to check my theory, you can read the ref count with
G_OBJECT(button->gobj())->ref_count, although you're not really supposed
to do that. ref_count is marked as private data in GObject, and I can
find no function you can use to read it.
Kjell
Hi, in documentation (i.e official gtkmm tutorial) I have found this:
get_widget() returns child widgets that are manage()ed (see the Memory Management chapter), so they will be deleted when their parent container is deleted. So, if you get only a child widget from Gtk::Builder, instead of a whole window, then you must either put it in a Container or delete it. Windows (such asDialogs) cannot be managed because they have no parent container, so you must delete them at some point.
But I do not fully understand it. In first part it tells that widget dies with window. So when I retrieve a window and delete it, it will delete widgets.. but when I retrieve window and widget, the widget will not be deleted. Am I right? So why treeview is deleted after deleting the window and button is not? I get pointer to treeview the same way I get pointer to button.
P.S. I'm sorry Kjell for duplicated mail, I forgot to leave mailing list in CC ;)
--
-----------------------------------------------------------
Krzysztof Łochwinowicz
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]