35 static void gnc_gobject_weak_cb (gpointer user_data, GObject *
object);
51 gnc_gobject_tracking_table (
void)
53 static GHashTable *singleton = NULL;
57 singleton = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
72 gnc_gobject_dump_gobject (GObject *
object,
const gchar *name)
75 PINFO(
" object %p, ref count %d",
object, object->ref_count);
87 gnc_gobject_dump_list (
const gchar *name, GList *list, gpointer user_data)
90 PINFO(
" %d %s", g_list_length(list), name);
91 g_list_foreach(list, (GFunc)gnc_gobject_dump_gobject, (gpointer)name);
109 table = gnc_gobject_tracking_table();
111 if (g_hash_table_size(
table) > 0)
113 PINFO(
"The following objects remain alive:");
114 g_hash_table_foreach_remove(
table, (GHRFunc)gnc_gobject_dump_list, NULL);
125 g_return_if_fail(G_IS_OBJECT(
object));
127 GObjectClass *klass = G_OBJECT_GET_CLASS(
object);
128 const gchar *name = g_type_name(G_TYPE_FROM_CLASS(klass));
131 GHashTable *
table = gnc_gobject_tracking_table();
132 GList *list = g_hash_table_lookup(
table, name);
134 if (g_list_index(list,
object) != -1)
136 g_critical(
"Object %p is already in list of %s",
object, name);
141 list = g_list_append(list,
object);
142 g_hash_table_insert(
table, g_strdup(name), list);
144 g_object_weak_ref(
object, gnc_gobject_weak_cb, NULL);
150 gnc_gobject_tracking_forget_internal (GObject *
object)
156 g_return_val_if_fail(G_IS_OBJECT(
object), FALSE);
158 name = G_OBJECT_TYPE_NAME(
object);
160 table = gnc_gobject_tracking_table();
161 list = g_hash_table_lookup(
table, name);
168 item = g_list_find(list,
object);
176 list = g_list_remove_link(list, item);
179 g_hash_table_replace(
table, g_strdup(name), list);
184 g_hash_table_remove(
table, name);
196 if (gnc_gobject_tracking_forget_internal(
object))
197 g_object_weak_unref(
object, gnc_gobject_weak_cb, NULL);
211 gnc_gobject_weak_cb (gpointer user_data, GObject *
object)
213 gnc_gobject_tracking_forget_internal(
object);
226 table = gnc_gobject_tracking_table();
227 list = g_hash_table_lookup(
table, name);
const GList * gnc_gobject_tracking_get_list(const gchar *name)
Get a list of all known objects of a specified type.
void gnc_gobject_tracking_dump(void)
Dump the entire object tracking database via the g_log() family of functions.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define PINFO(format, args...)
Print an informational note.
void gnc_gobject_tracking_forget(GObject *object)
Tell gnucash to remember this object in the database.
void gnc_gobject_tracking_remember(GObject *object)
Tell gnucash to remember this object in the database.