[gnome-photos/wip/rishi/misc-fixes: 11/18] tracker-collections-controller: Break a reference cycle



commit 8197ba72da26c88b7fa605989eea9cb78dac85c2
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Dec 14 19:07:58 2015 +0100

    tracker-collections-controller: Break a reference cycle

 src/photos-tracker-collections-controller.c |   37 ++++++++++++++++++++------
 1 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-tracker-collections-controller.c b/src/photos-tracker-collections-controller.c
index 23d0607..220b26d 100644
--- a/src/photos-tracker-collections-controller.c
+++ b/src/photos-tracker-collections-controller.c
@@ -79,14 +79,16 @@ photos_tracker_collections_controller_get_query (PhotosTrackerController *trk_cn
   GApplication *app;
   PhotosBaseItem *collection;
   PhotosSearchContextState *state;
-  gint flags;
+  gint flags = PHOTOS_QUERY_FLAGS_COLLECTIONS;
+
+  if (priv->item_mngr == NULL)
+    goto end;
 
   collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (priv->item_mngr));
   if (collection != NULL)
     flags = PHOTOS_QUERY_FLAGS_NONE;
-  else
-    flags = PHOTOS_QUERY_FLAGS_COLLECTIONS;
 
+ end:
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
@@ -118,17 +120,30 @@ static void
 photos_tracker_collections_controller_dispose (GObject *object)
 {
   PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (object);
-  PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
 
-  g_clear_object (&priv->item_mngr);
-  g_clear_object (&priv->mode_cntrlr);
-  g_clear_object (&priv->offset_cntrlr);
+  g_clear_object (&self->priv->offset_cntrlr);
 
   G_OBJECT_CLASS (photos_tracker_collections_controller_parent_class)->dispose (object);
 }
 
 
 static void
+photos_tracker_collections_controller_finalize (GObject *object)
+{
+  PhotosTrackerCollectionsController *self = PHOTOS_TRACKER_COLLECTIONS_CONTROLLER (object);
+  PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
+
+  if (priv->item_mngr != NULL)
+    g_object_remove_weak_pointer (G_OBJECT (priv->item_mngr), (gpointer *) &priv->item_mngr);
+
+  if (priv->mode_cntrlr != NULL)
+    g_object_remove_weak_pointer (G_OBJECT (priv->mode_cntrlr), (gpointer *) &priv->mode_cntrlr);
+
+  G_OBJECT_CLASS (photos_tracker_collections_controller_parent_class)->finalize (object);
+}
+
+
+static void
 photos_tracker_collections_controller_init (PhotosTrackerCollectionsController *self)
 {
   PhotosTrackerCollectionsControllerPrivate *priv;
@@ -141,13 +156,16 @@ photos_tracker_collections_controller_init (PhotosTrackerCollectionsController *
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  priv->item_mngr = g_object_ref (state->item_mngr);
+  priv->item_mngr = state->item_mngr;
+  g_object_add_weak_pointer (G_OBJECT (priv->item_mngr), (gpointer *) &priv->item_mngr);
   g_signal_connect_swapped (priv->item_mngr,
                             "active-collection-changed",
                             G_CALLBACK (photos_tracker_collections_controller_col_active_changed),
                             self);
 
-  priv->mode_cntrlr = g_object_ref (state->mode_cntrlr);
+  priv->mode_cntrlr = state->mode_cntrlr;
+  g_object_add_weak_pointer (G_OBJECT (priv->mode_cntrlr), (gpointer *) &priv->mode_cntrlr);
+
   priv->offset_cntrlr = photos_offset_collections_controller_dup_singleton ();
 }
 
@@ -160,6 +178,7 @@ photos_tracker_collections_controller_class_init (PhotosTrackerCollectionsContro
 
   object_class->constructor = photos_tracker_collections_controller_constructor;
   object_class->dispose = photos_tracker_collections_controller_dispose;
+  object_class->finalize = photos_tracker_collections_controller_finalize;
   tracker_controller_class->get_offset_controller = 
photos_tracker_collections_controller_get_offset_controller;
   tracker_controller_class->get_query = photos_tracker_collections_controller_get_query;
 }


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