[PATCH 2/2] Fix VarsTreeView memory management



Hello,

When using Nemiver from master on GNOME 3, I noticed warnings like
this in the terminal:

    g_object_unref: assertion `G_IS_OBJECT (object)' failed

As often, it turned out this is due to some memory management issue.
The VarsTreeView widget is reused in the following components:
LocalVarsInspector, GlobalVarsInspector and VarInspectorDialog.  These
components hand out the VarsTreeView widget which eventually gets packed
into some other composite container.  Obviously the VarsTreeView should
be handled by Gtk::manage so that when the composite container is
destroyed, the VarsTreeView gets destroyed too.

The problem in this case was that instead of using Gtk::manage, the
relevant componts were using SafePtrs to handle the life cycle of the
VarsTreeView.  This patch fixes that.

Tested on GNOME 3, applied to master.

>From 71d37236be8178c9eaa44f7c4a58c3e3f0ad5ab1 Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <dodji gnome org>
Date: Sat, 11 Jun 2011 20:48:15 +0200
Subject: [PATCH 2/2] Fix VarsTreeView memory management

	* src/persp/dbgperspective/nmv-vars-treeview.h
	(VarsTreeView::create): Change return type from a SafePtr to a
	bare VarsTreeView* pointer.
	* src/persp/dbgperspective/nmv-vars-treeview.cc
	(VarsTreeView::create): Likewise.  Return a VarsTreeView* now.
	The caller has either to call Gtk::manage on the result of
	VarsTreeView::create or delete it by hand.
	* src/persp/dbgperspective/nmv-local-vars-inspector.cc
	(LocalVarsInspector::Priv::tree_view): Change the type of this
	member from a SafePtr to a bare VarsTreeView* pointer.
	(LocalVarsInspector::Priv::Priv):
	Initialize LocalVarsInspector::Priv::tree_view with the result of
	VarsTreeView passed to Gtk::manage.  Avoid doing the (wrong)
	tree_view.reference() dance I was doing before.
	* src/persp/dbgperspective/nmv-global-vars-inspector-dialog.cc
	(GlobalVarsInspectorDialog::Priv::tree_view): Change the type of
	this member from a SafePtr to a bare VarsTreeView* pointer.
	* src/uicommon/nmv-dialog.cc (Dialog::Priv::Priv): Fix indentation.
---
 .../nmv-global-vars-inspector-dialog.cc            |    5 +++--
 .../dbgperspective/nmv-local-vars-inspector.cc     |    8 ++------
 src/persp/dbgperspective/nmv-var-inspector.cc      |    5 +++--
 src/persp/dbgperspective/nmv-vars-treeview.cc      |    4 ++--
 src/persp/dbgperspective/nmv-vars-treeview.h       |    2 +-
 src/uicommon/nmv-dialog.cc                         |    2 +-
 6 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/persp/dbgperspective/nmv-global-vars-inspector-dialog.cc b/src/persp/dbgperspective/nmv-global-vars-inspector-dialog.cc
index 4556bf7..03a944c 100644
--- a/src/persp/dbgperspective/nmv-global-vars-inspector-dialog.cc
+++ b/src/persp/dbgperspective/nmv-global-vars-inspector-dialog.cc
@@ -50,7 +50,7 @@ public:
     IVarListWalkerSafePtr global_variables_walker_list;
 
     IWorkbench &workbench;
-    VarsTreeViewSafePtr tree_view;
+    VarsTreeView* tree_view;
     Glib::RefPtr<Gtk::TreeStore> tree_store;
     Gtk::TreeModel::iterator cur_selected_row;
     SafePtr<Gtk::Menu> contextual_menu;
@@ -62,7 +62,8 @@ public:
           IWorkbench &a_workbench) :
         dialog (a_dialog),
         gtkbuilder (a_gtkbuilder),
-        workbench (a_workbench)
+        workbench (a_workbench),
+        tree_view (0)
     {
         LOG_FUNCTION_SCOPE_NORMAL_DD;
 
diff --git a/src/persp/dbgperspective/nmv-local-vars-inspector.cc b/src/persp/dbgperspective/nmv-local-vars-inspector.cc
index 2a12e84..a33c960 100644
--- a/src/persp/dbgperspective/nmv-local-vars-inspector.cc
+++ b/src/persp/dbgperspective/nmv-local-vars-inspector.cc
@@ -52,7 +52,7 @@ public:
     IDebuggerSafePtr debugger;
     IWorkbench &workbench;
     IPerspective &perspective;
-    VarsTreeViewSafePtr tree_view;
+    VarsTreeView *tree_view;
     Glib::RefPtr<Gtk::TreeStore> tree_store;
     Gtk::TreeModel::iterator cur_selected_row;
     SafePtr<Gtk::TreeRowReference> local_variables_row_ref;
@@ -83,7 +83,7 @@ public:
           IPerspective& a_perspective) :
         workbench (a_workbench),
         perspective (a_perspective),
-        tree_view (VarsTreeView::create ()),
+        tree_view (Gtk::manage (VarsTreeView::create ())),
         is_new_frame (false),
         is_up2date (true),
         saved_reason (IDebugger::UNDEFINED_REASON),
@@ -93,10 +93,6 @@ public:
         module_manager (0)
     {
         LOG_FUNCTION_SCOPE_NORMAL_DD;
-        // We are going to unref the tree_view when an instance of
-        // this type is going to be distroyed.  So we need to hold a
-        // reference on tree_view.
-        tree_view.reference ();
         THROW_IF_FAIL (a_debugger);
         debugger = a_debugger;
         THROW_IF_FAIL (tree_view);
diff --git a/src/persp/dbgperspective/nmv-var-inspector.cc b/src/persp/dbgperspective/nmv-var-inspector.cc
index f7684ce..e37f2f6 100644
--- a/src/persp/dbgperspective/nmv-var-inspector.cc
+++ b/src/persp/dbgperspective/nmv-var-inspector.cc
@@ -58,7 +58,7 @@ class VarInspector::Priv : public sigc::trackable {
     // at a given point in time
     IDebugger::VariableSafePtr variable;
     IPerspective &perspective;
-    VarsTreeViewSafePtr tree_view;
+    VarsTreeView *tree_view;
     Glib::RefPtr<Gtk::TreeStore> tree_store;
     Gtk::TreeModel::iterator var_row_it;
     Gtk::TreeModel::iterator cur_selected_row;
@@ -72,7 +72,7 @@ class VarInspector::Priv : public sigc::trackable {
     build_widget ()
     {
         LOG_FUNCTION_SCOPE_NORMAL_DD;
-        tree_view = VarsTreeView::create ();
+        tree_view = Gtk::manage (VarsTreeView::create ());
         THROW_IF_FAIL (tree_view);
         tree_store = tree_view->get_tree_store ();
         THROW_IF_FAIL (tree_store);
@@ -583,6 +583,7 @@ public:
           enable_contextual_menu (false),
           debugger (a_debugger),
           perspective (a_perspective),
+          tree_view (0),
           var_inspector_menu (0),
           module_manager (0)
     {
diff --git a/src/persp/dbgperspective/nmv-vars-treeview.cc b/src/persp/dbgperspective/nmv-vars-treeview.cc
index 04f0c50..cc192e3 100644
--- a/src/persp/dbgperspective/nmv-vars-treeview.cc
+++ b/src/persp/dbgperspective/nmv-vars-treeview.cc
@@ -31,13 +31,13 @@ namespace vutil = nemiver::variables_utils2;
 
 NEMIVER_BEGIN_NAMESPACE (nemiver)
 
-VarsTreeViewSafePtr
+VarsTreeView*
 VarsTreeView::create ()
 {
     Glib::RefPtr<Gtk::TreeStore> model =
         Gtk::TreeStore::create (vutil::get_variable_columns ());
     THROW_IF_FAIL (model);
-    return VarsTreeViewSafePtr(new VarsTreeView (model));
+    return new VarsTreeView (model);
 }
 
 VarsTreeView::VarsTreeView (Glib::RefPtr<Gtk::TreeStore>& model) :
diff --git a/src/persp/dbgperspective/nmv-vars-treeview.h b/src/persp/dbgperspective/nmv-vars-treeview.h
index 3be799d..d9c0324 100644
--- a/src/persp/dbgperspective/nmv-vars-treeview.h
+++ b/src/persp/dbgperspective/nmv-vars-treeview.h
@@ -47,7 +47,7 @@ class NEMIVER_API VarsTreeView : public Gtk::TreeView
             VARIABLE_VALUE_COLUMN_INDEX,
             VARIABLE_TYPE_COLUMN_INDEX
         };
-        static VarsTreeViewSafePtr create ();
+        static VarsTreeView* create ();
         Glib::RefPtr<Gtk::TreeStore>& get_tree_store ();
 
     protected:
diff --git a/src/uicommon/nmv-dialog.cc b/src/uicommon/nmv-dialog.cc
index 3fe1841..f699432 100644
--- a/src/uicommon/nmv-dialog.cc
+++ b/src/uicommon/nmv-dialog.cc
@@ -70,7 +70,7 @@ public:
         THROW_IF_FAIL (gtkbuilder);
         dialog.reset
             (ui_utils::get_widget_from_gtkbuilder<Gtk::Dialog> (gtkbuilder,
-                                                           a_widget_name));
+                                                                a_widget_name));
         THROW_IF_FAIL (dialog);
     }
 };//end struct Dialog::Priv
-- 
		Dodji


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]