[gedit] Don't leak the last GeditView on application shutdown
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Don't leak the last GeditView on application shutdown
- Date: Mon, 7 Jul 2014 14:24:26 +0000 (UTC)
commit a1969c8473776f1ebb897760d90a22f370154062
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 7 16:18:16 2014 +0200
Don't leak the last GeditView on application shutdown
At first I thought all GeditView were leaked, so I searched where a ref
of GeditView is not released, and I've finally found.
But after some testing, only the last GeditView of the application is
leaked, because an unref in GIO must be executed in an idle, and the
idle is not executed on application shutdown.
So even if the leak was not really a leak, this commit will make
debugging memory leaks a bit nicer, and will hopefully save some time
for next developers.
gedit/gedit-window.c | 37 +++++++++++++++++++++++++++----------
1 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 41b594a..1dc550a 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -90,6 +90,9 @@ static const GtkTargetEntry drop_types [] = {
G_DEFINE_TYPE_WITH_PRIVATE (GeditWindow, gedit_window, GTK_TYPE_APPLICATION_WINDOW)
+/* Prototypes */
+static void remove_actions (GeditWindow *window);
+
static void
gedit_window_get_property (GObject *object,
guint prop_id,
@@ -226,6 +229,15 @@ gedit_window_dispose (GObject *object)
g_clear_object (&window->priv->side_stack_switcher);
+ /* GTK+/GIO unref the action map in an idle. For the last GeditWindow,
+ * the application quits before the idle, so the action map is not
+ * unreffed, and some objects are not finalized on application shutdown
+ * (GeditView for example).
+ * So this is just for making the debugging of object references a bit
+ * nicer.
+ */
+ remove_actions (window);
+
G_OBJECT_CLASS (gedit_window_parent_class)->dispose (object);
}
@@ -1187,24 +1199,29 @@ static GActionEntry text_wrapping_entrie[] = {
};
static void
+remove_actions (GeditWindow *window)
+{
+ g_action_map_remove_action (G_ACTION_MAP (window), "auto-indent");
+ g_action_map_remove_action (G_ACTION_MAP (window), "tab-width");
+ g_action_map_remove_action (G_ACTION_MAP (window), "use-spaces");
+ g_action_map_remove_action (G_ACTION_MAP (window), "show-line-numbers");
+ g_action_map_remove_action (G_ACTION_MAP (window), "display-right-margin");
+ g_action_map_remove_action (G_ACTION_MAP (window), "highlight-current-line");
+ g_action_map_remove_action (G_ACTION_MAP (window), "wrap-mode");
+}
+
+static void
sync_current_tab_actions (GeditWindow *window,
GeditView *old_view,
GeditView *new_view)
{
- if (old_view)
+ if (old_view != NULL)
{
- g_action_map_remove_action (G_ACTION_MAP (window), "auto-indent");
- g_action_map_remove_action (G_ACTION_MAP (window), "tab-width");
- g_action_map_remove_action (G_ACTION_MAP (window), "use-spaces");
- g_action_map_remove_action (G_ACTION_MAP (window), "show-line-numbers");
- g_action_map_remove_action (G_ACTION_MAP (window), "display-right-margin");
- g_action_map_remove_action (G_ACTION_MAP (window), "highlight-current-line");
- g_action_map_remove_action (G_ACTION_MAP (window), "wrap-mode");
-
+ remove_actions (window);
g_signal_handler_disconnect (old_view, window->priv->wrap_mode_changed_id);
}
- if (new_view)
+ if (new_view != NULL)
{
GPropertyAction *action;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]