Files | |
| file | gnc-gobject-utils.h |
| Gobject helper routines. | |
Gobject Tracking Functions | |
| This set of functions is used to maintain a "database" of objects that are built on top of a GObject (any level of nesting). This database is simply a hash table of lists. The hash table takes the object name as its key and returns a list of all objects of that type. The object is then added to, deleted from, or looked up in the list. The database can also be queried for a list of all objects of a specified type. This can be used to find pre-existing GncTreeModels, etc. (In this case performing a search for a specific object wouldn't help because the information being inspected is private to the object.)
Any object added to this databasse during the execution of gnucash should be deleted from it before completion of the program. WHen the program shuts down, a list of all abjects still in the database will be dumped out to the logfile. This should help developers find memoty leaks in their code where an object is lost, or is not release because it gained an extra reference at some point during its lifetime. | |
| void | gnc_gobject_tracking_remember (GObject *object, GObjectClass *klass) |
| void | gnc_gobject_tracking_forget (GObject *object) |
| const GList * | gnc_gobject_tracking_get_list (const gchar *name) |
| void | gnc_gobject_tracking_dump (void) |
| void gnc_gobject_tracking_dump | ( | void | ) |
Dump the entire object tracking database via the g_log() family of functions. This function is only called when gnucash exits, and at that point all of the objects should have been removed from the database and freed. Any object remaining is the result of a memory/object leakage.
Definition at line 104 of file gnc-gobject-utils.c.
00105 { 00106 GHashTable *table; 00107 00108 //printf("Enter %s:\n", __FUNCTION__); 00109 table = gnc_gobject_tracking_table(); 00110 00111 if (g_hash_table_size(table) > 0) { 00112 g_message("The following objects remain alive:"); 00113 g_hash_table_foreach_remove(table, (GHRFunc)gnc_gobject_dump_list, NULL); 00114 } 00115 //printf("Leave %s:\n", __FUNCTION__); 00116 }
| void gnc_gobject_tracking_forget | ( | GObject * | object | ) |
Tell gnucash to remember this object in the database.
Definition at line 196 of file gnc-gobject-utils.c.
00197 { 00198 if (gnc_gobject_tracking_forget_internal(object)) 00199 g_object_weak_unref(object, gnc_gobject_weak_cb, NULL); 00200 }
| const GList* gnc_gobject_tracking_get_list | ( | const gchar * | name | ) |
Get a list of all known objects of a specified type.
Definition at line 222 of file gnc-gobject-utils.c.
00223 { 00224 GHashTable *table; 00225 GList *list; 00226 00227 //printf("Enter %s: name %s\n", __FUNCTION__, name); 00228 table = gnc_gobject_tracking_table(); 00229 list = g_hash_table_lookup(table, name); 00230 //printf("Leave %s: list %p\n", __FUNCTION__, list); 00231 return list; 00232 }
| void gnc_gobject_tracking_remember | ( | GObject * | object, | |
| GObjectClass * | klass | |||
| ) |
Tell gnucash to remember this object in the database.
Definition at line 122 of file gnc-gobject-utils.c.
00123 { 00124 GHashTable *table; 00125 GList *list; 00126 const gchar *name; 00127 00128 g_return_if_fail(G_IS_OBJECT(object)); 00129 00130 /* Little dance here to handle startup conditions. During object 00131 * initialization the object type changes as each each parent class 00132 * is initialized. The class passed to the initialization function 00133 * is always the ultimate class of the object. */ 00134 if (klass == NULL) 00135 klass = G_OBJECT_GET_CLASS(object); 00136 name = g_type_name(G_TYPE_FROM_CLASS(klass)); 00137 00138 //printf("Enter %s: object %p of type %s\n", __FUNCTION__, object, name); 00139 table = gnc_gobject_tracking_table(); 00140 list = g_hash_table_lookup(table, name); 00141 00142 if (g_list_index(list, object) != -1) { 00143 g_critical("Object %p is already in list of %s", object, name); 00144 //printf("Leave %s: already in list\n", __FUNCTION__); 00145 return; 00146 } 00147 00148 list = g_list_append(list, object); 00149 g_hash_table_insert(table, g_strdup(name), list); 00150 00151 g_object_weak_ref(object, gnc_gobject_weak_cb, NULL); 00152 //printf("Leave %s:\n", __FUNCTION__); 00153 }
1.5.2