[gnome-photos/wip/rishi/misc-fixes: 4/20] tracker-collections-controller: Break a reference cycle
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/misc-fixes: 4/20] tracker-collections-controller: Break a reference cycle
- Date: Tue, 15 Dec 2015 20:08:59 +0000 (UTC)
commit f9a8702d8a3e0f393b94d9d05df399f7cf7faf86
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 | 36 +++++++++++++++++++++-----
1 files changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-tracker-collections-controller.c b/src/photos-tracker-collections-controller.c
index 23d0607..ee55277 100644
--- a/src/photos-tracker-collections-controller.c
+++ b/src/photos-tracker-collections-controller.c
@@ -53,9 +53,12 @@ G_DEFINE_TYPE_WITH_CODE (PhotosTrackerCollectionsController,
static void
photos_tracker_collections_controller_col_active_changed (PhotosTrackerCollectionsController *self)
{
+ PhotosTrackerCollectionsControllerPrivate *priv = self->priv;
PhotosWindowMode mode;
- mode = photos_mode_controller_get_window_mode (self->priv->mode_cntrlr);
+ g_return_if_fail (priv->mode_cntrlr != NULL);
+
+ mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
if (mode != PHOTOS_WINDOW_MODE_COLLECTIONS)
return;
@@ -81,6 +84,8 @@ photos_tracker_collections_controller_get_query (PhotosTrackerController *trk_cn
PhotosSearchContextState *state;
gint flags;
+ g_return_val_if_fail (priv->item_mngr != NULL, NULL);
+
collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (priv->item_mngr));
if (collection != NULL)
flags = PHOTOS_QUERY_FLAGS_NONE;
@@ -118,17 +123,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 +159,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 +181,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]