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.
This commit is contained in:
Michael Natterer 2010-02-10 12:33:30 +01:00
parent 7bfa3272ab
commit 68ee4a5d6c
3 changed files with 41 additions and 1 deletions

View File

@ -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 ();

View File

@ -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);

View File

@ -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,