diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2014-01-09 17:21:43 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2014-01-22 17:10:06 +0100 |
commit | 31042fe95f73e0e93a5e7fb1584be72f6be667f2 (patch) | |
tree | 796fff42ca444ed5515c4e3165d0fcf562ac11c3 /gtk/gtktexthandle.c | |
parent | 342c23da236fdca7a3261cebf903adaf182355ab (diff) | |
download | gtk+-31042fe95f73e0e93a5e7fb1584be72f6be667f2.tar.gz |
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
Diffstat (limited to 'gtk/gtktexthandle.c')
-rw-r--r-- | gtk/gtktexthandle.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/gtk/gtktexthandle.c b/gtk/gtktexthandle.c index af73f58bf7..70de3b7a32 100644 --- a/gtk/gtktexthandle.c +++ b/gtk/gtktexthandle.c @@ -237,7 +237,7 @@ _gtk_text_handle_ensure_widget (GtkTextHandle *handle, G_CALLBACK (gtk_text_handle_widget_style_updated), handle); - priv->windows[pos].widget = widget; + priv->windows[pos].widget = g_object_ref_sink (widget); window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW); gtk_window_add_popover (GTK_WINDOW (window), widget); } @@ -305,11 +305,12 @@ gtk_text_handle_finalize (GObject *object) priv = GTK_TEXT_HANDLE (object)->priv; + /* We sank the references, unref here */ if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget) - gtk_widget_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget); + g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget); if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget) - gtk_widget_destroy (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget); + g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget); G_OBJECT_CLASS (_gtk_text_handle_parent_class)->finalize (object); } |