33 static void gnc_gobject_weak_cb (gpointer user_data, GObject *
object);
49 gnc_gobject_tracking_table (
void)
51 static GHashTable *singleton = NULL;
55 singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
70 gnc_gobject_dump_gobject (GObject *
object,
const gchar *name)
73 g_message(
" object %p, ref count %d",
object, object->ref_count);
85 gnc_gobject_dump_list (
const gchar *name, GList *list, gpointer user_data)
88 g_message(
" %d %s", g_list_length(list), name);
89 g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
107 table = gnc_gobject_tracking_table();
109 if (g_hash_table_size(table) > 0)
111 g_message(
"The following objects remain alive:");
112 g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL);
127 g_return_if_fail(G_IS_OBJECT(
object));
134 klass = G_OBJECT_GET_CLASS(
object);
135 name = g_type_name(G_TYPE_FROM_CLASS(klass));
138 table = gnc_gobject_tracking_table();
139 list = g_hash_table_lookup(table, name);
141 if (g_list_index(list,
object) != -1)
143 g_critical(
"Object %p is already in list of %s",
object, name);
148 list = g_list_append(list,
object);
149 g_hash_table_insert(table, g_strdup(name), list);
151 g_object_weak_ref(
object, gnc_gobject_weak_cb, NULL);
157 gnc_gobject_tracking_forget_internal (GObject *
object)
163 g_return_val_if_fail(G_IS_OBJECT(
object), FALSE);
165 name = G_OBJECT_TYPE_NAME(
object);
167 table = gnc_gobject_tracking_table();
168 list = g_hash_table_lookup(table, name);
175 item = g_list_find(list,
object);
183 list = g_list_remove_link(list, item);
186 g_hash_table_replace(table, g_strdup(name), list);
191 g_hash_table_remove(table, name);
203 if (gnc_gobject_tracking_forget_internal(
object))
204 g_object_weak_unref(
object, gnc_gobject_weak_cb, NULL);
218 gnc_gobject_weak_cb (gpointer user_data, GObject *
object)
220 gnc_gobject_tracking_forget_internal(
object);
233 table = gnc_gobject_tracking_table();
234 list = g_hash_table_lookup(table, name);
const GList * gnc_gobject_tracking_get_list(const gchar *name)
void gnc_gobject_tracking_dump(void)
void gnc_gobject_tracking_remember(GObject *object, GObjectClass *klass)
void gnc_gobject_tracking_forget(GObject *object)