[gimp] base: add a proper version of the code that tracked down the tile manager leak



commit 68ee4a5d6c594afe676b0a8a46159046157f85aa
Author: Michael Natterer <mitch gimp org>
Date:   Wed Feb 10 12:33:30 2010 +0100

    base: add a proper version of the code that tracked down the tile manager leak
    
    For GIMP_UNSTABLE, keep around a list of allocated tile managers and
    have a function tile_manager_exit() which complains about them and
    unrefs them. This is infinitely more helpful than the tile cache and
    swap complaining about not being empty, because there is absolutely
    nothing wrong with swap and cache when we simply leaked tile managers.

 app/base/base.c         |    5 +++++
 app/base/tile-manager.c |   34 +++++++++++++++++++++++++++++++++-
 app/base/tile-manager.h |    3 +++
 3 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/app/base/base.c b/app/base/base.c
index 34f2345..9d32454 100644
--- a/app/base/base.c
+++ b/app/base/base.c
@@ -40,6 +40,7 @@
 #include "base.h"
 #include "pixel-processor.h"
 #include "tile-cache.h"
+#include "tile-manager.h"
 #include "tile-swap.h"
 
 
@@ -116,6 +117,10 @@ base_exit (void)
 {
   g_return_if_fail (base_config != NULL);
 
+#ifdef GIMP_UNSTABLE
+  tile_manager_exit ();
+#endif
+
   pixel_processor_exit ();
   paint_funcs_free ();
   tile_cache_exit ();
diff --git a/app/base/tile-manager.c b/app/base/tile-manager.c
index 1186781..556498c 100644
--- a/app/base/tile-manager.c
+++ b/app/base/tile-manager.c
@@ -39,6 +39,11 @@ extern gint tile_exist_peak;
 extern gint tile_exist_count;
 #endif
 
+#ifdef GIMP_UNSTABLE
+GList *tile_managers = NULL;
+#endif
+
+
 GType
 gimp_tile_manager_get_type (void)
 {
@@ -52,6 +57,26 @@ gimp_tile_manager_get_type (void)
   return type;
 }
 
+#ifdef GIMP_UNSTABLE
+void
+tile_manager_exit (void)
+{
+  if (tile_managers)
+    {
+      g_warning ("%d tile managers leaked", g_list_length (tile_managers));
+
+      while (tile_managers)
+        {
+          g_printerr ("unref tile manager %p (%d x %d)\n",
+                      tile_managers->data,
+                      tile_manager_width (tile_managers->data),
+                      tile_manager_height (tile_managers->data));
+
+          tile_manager_unref (tile_managers->data);
+        }
+    }
+}
+#endif
 
 static inline gint
 tile_manager_get_tile_num (TileManager *tm,
@@ -65,7 +90,6 @@ tile_manager_get_tile_num (TileManager *tm,
   return (ypixel / TILE_HEIGHT) * tm->ntile_cols + (xpixel / TILE_WIDTH);
 }
 
-
 TileManager *
 tile_manager_new (gint width,
                   gint height,
@@ -86,6 +110,10 @@ tile_manager_new (gint width,
   tm->ntile_cols  = (width  + TILE_WIDTH  - 1) / TILE_WIDTH;
   tm->cached_num  = -1;
 
+#ifdef GIMP_UNSTABLE
+  tile_managers = g_list_prepend (tile_managers, tm);
+#endif
+
   return tm;
 }
 
@@ -108,6 +136,10 @@ tile_manager_unref (TileManager *tm)
 
   if (tm->ref_count < 1)
     {
+#ifdef GIMP_UNSTABLE
+      tile_managers = g_list_remove (tile_managers, tm);
+#endif
+
       if (tm->cached_tile)
         tile_release (tm->cached_tile, FALSE);
 
diff --git a/app/base/tile-manager.h b/app/base/tile-manager.h
index 17d6d23..40b5045 100644
--- a/app/base/tile-manager.h
+++ b/app/base/tile-manager.h
@@ -24,6 +24,9 @@
 
 GType         gimp_tile_manager_get_type     (void) G_GNUC_CONST;
 
+#ifdef GIMP_UNSTABLE
+void          tile_manager_exit              (void);
+#endif
 
 /* Creates a new tile manager with the specified size */
 TileManager * tile_manager_new               (gint width,



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