[tracker/wip/carlosg/dispose-resources] libtracker-sparql: Implement dispose() in TrackerResource



commit 17cdad27df060c62b93e2615c4a27f269b134346
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Aug 10 12:31:01 2019 +0200

    libtracker-sparql: Implement dispose() in TrackerResource
    
    TrackerResource may in some circumstances contain links to itself, or other
    reference cycles. We should eventually offer a destroy() method, but
    implementing dispose() will at least provide a tool to ensure those cycles
    are gone.

 src/libtracker-sparql/tracker-resource.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 989fafb65..9c9fd53aa 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -74,6 +74,7 @@ enum {
        PROP_IDENTIFIER,
 };
 
+static void dispose      (GObject *object);
 static void constructed  (GObject *object);
 static void finalize     (GObject *object);
 static void get_property (GObject    *object,
@@ -91,6 +92,7 @@ tracker_resource_class_init (TrackerResourceClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+       object_class->dispose      = dispose;
        object_class->constructed  = constructed;
        object_class->finalize     = finalize;
        object_class->get_property = get_property;
@@ -115,6 +117,8 @@ tracker_resource_class_init (TrackerResourceClass *klass)
 static void
 free_value (GValue *value)
 {
+       if (G_VALUE_TYPE (value) == TRACKER_TYPE_RESOURCE)
+               g_object_run_dispose (g_value_get_object (value));
        g_value_unset (value);
        g_slice_free (GValue, value);
 }
@@ -139,6 +143,19 @@ tracker_resource_init (TrackerResource *resource)
                NULL);
 }
 
+static void
+dispose (GObject *object)
+{
+       TrackerResourcePrivate *priv;
+
+       priv = GET_PRIVATE (TRACKER_RESOURCE (object));
+
+       g_hash_table_remove_all (priv->overwrite);
+       g_hash_table_remove_all (priv->properties);
+
+       G_OBJECT_CLASS (tracker_resource_parent_class)->dispose (object);
+}
+
 static void
 constructed (GObject *object)
 {


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