Re: Problem with memory management with builder.
- From: Kjell Ahlstedt <kjell ahlstedt bredband net>
- To: Krzysztof Łochwinowicz <krzysztof lochwinowicz gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Problem with memory management with builder.
- Date: Mon, 20 Jun 2011 11:58:06 +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
tor 2011-06-16 klockan 11:51 +0200 skrev Krzysztof Łochwinowicz:
> Hi Krzysztof,
> Deleting an already deleted object will not always be
> guaranteed to
> cause obvious problems like a segmentation fault.
> Sometimes, depending
> on what order objects are created in and whether you
> try to do anything
> after the delete, you may see no apparent problem. Try
> adding some heap
> activity between the delete window and the delete
> button; you may be
> able to provoke the crash that way. Or run it with
> valgrind, which
> should report the double-delete whether it would
> actually crash or not.
>
> Cheers,
> Rob
>
> I do some heap activity but it does not change anything. I run
> valgrind. See attached log. There is no invalid free.
> -----------------------------------------------------------
> Krzysztof Łochwinowicz
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]