diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 028206a..8433b52 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -1026,9 +1026,67 @@ camel_folder_class_init (CamelFolderClass *class)
 		G_TYPE_STRING);
 }
 
+#if 1
+
+GStaticMutex data_lock = G_STATIC_MUTEX_INIT;
+GHashTable *objects = NULL;
+
 static void
-camel_folder_init (CamelFolder *folder)
+object_dump (gpointer obj)
+{
+	g_return_if_fail (G_IS_OBJECT (obj));
+	fprintf (stderr, "\t%p\t%s\t%d", obj,
+		 g_type_name_from_instance (obj),
+		 ((GObject *)obj)->ref_count);
+	if (CAMEL_IS_FOLDER (obj)) {
+		fprintf (stderr, "\t'%s'\t'%s'",
+			 camel_folder_get_name (CAMEL_FOLDER (obj)),
+			 camel_folder_get_full_name (CAMEL_FOLDER (obj)));
+	}
+	fprintf (stderr, "\n");
+}
+
+static void
+object_debug_leaks (void)
 {
+	fprintf (stderr, "%d objects leaked\n",
+		 g_hash_table_size (objects));
+	g_hash_table_foreach (objects, (GHFunc)object_dump, NULL);
+}
+
+static void
+object_release (gpointer data,
+		GObject *where_the_object_was)
+{
+	g_static_mutex_lock (&data_lock);
+	g_hash_table_remove (objects, where_the_object_was);
+	g_static_mutex_unlock (&data_lock);
+}
+
+static void
+object_debug_add (gpointer object)
+{
+	static int init = 0;
+	g_static_mutex_lock (&data_lock);
+
+	if (!init) {
+		g_atexit (object_debug_leaks);
+		init = 1;
+		objects = g_hash_table_new (NULL, NULL);
+	}
+	g_hash_table_insert (objects, object, object);
+	g_object_weak_ref (object, object_release, NULL);
+
+	g_static_mutex_unlock (&data_lock);
+}
+#endif
+
+
+static void
+camel_folder_init (CamelFolder *folder)
+{	
+	object_debug_add (folder);
+
 	folder->priv = CAMEL_FOLDER_GET_PRIVATE (folder);
 
 	folder->priv->frozen = 0;
