Re: [gtk-list] GtkPixmap / Imlib memory leak problem
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] GtkPixmap / Imlib memory leak problem
- Date: Mon, 17 May 99 19:10:31 +0200
On Mon, 17 May 1999 15:09:05 +0100, gtk-list@redhat.com (Dave Swegen) wrote:
> I'm having a problem with a hideous memory leak. In my program I use imlib
> to load an image, then convert the image data to a pixmap, which in turn is
> converted to a GtkPixmap (using gtk_pixmap_new()).
Imlib's picture cache can also look like a memory leak...
> This all works fine. The problem arises whenever I wish to replace the
> gtkpixmap with a newly generated pixmap. It would seem that the GdkPixmap
> info in the gtkpixmap struct is just cut loose every time I update, and
> I've been completly unable to figure out how to free the pixmap.
For normal GTK generated pixmaps, use gdk_pixmap_unref() and
gdk_bitmap_unref(), for Imlib, use gdk_imlib_free_pixmap() and
gdk_imlib_free_bitmap().
> The order of the program is something like this:
>
> load_image() (using gdk_imlib)
>
> update_and_render image()
>
> display_pixmap()
>
> I then have a callback function, which is run whnever the mouse is clicked.
>
> The callback has the following sequence:
>
> flood_fill_area()
>
> update_and_render_image() <- Program size increases 3Mb every time called
>
> display_pixmap()
>
> The updating function looks like this:
>
> void update_map(world *worldobj, gui_info * gui)
> {
> GdkPixmap *pm;
>
> /* worldobj->map is a GdkImlibImage */
> gdk_imlib_changed_image(worldobj->map);
> gdk_imlib_render(worldobj->map,
> worldobj->map->rgb_width,
> worldobj->map->rgb_height);
> pm = gdk_imlib_move_image(worldobj->map);
> /* I suspect the old gdkpm is cut loose at the next line */
> gui->map_pm = gtk_pixmap_new(pm, NULL);
> worldobj->map_h = worldobj->map->rgb_height;
> worldobj->map_w = worldobj->map->rgb_width;
> gtk_fixed_put(GTK_FIXED(gui->fbox), gui->map_pm, 0, 0);
> gtk_widget_show(gui->map_pm);
> }
>
> According to the imlib docs gdk_imlib_free_pixmap should be called on all
> pixmaps created by imlib, but I have been unable to work out how to access
> the gdkpixmap which is held by the GtkPixmap (gui->map_pm, which is
> actually a GtkWidget).
>
> Calling gtk_destroy_widget(gui->map_pm) either has no effect, or causes a
> segfault.
>
> Anyway, I will appreciate any clarification on the matter.
In an application that displays uncompressed YUV 4:2:2 video data, I use:
void render_and_update(GtkWidget *pixmap, unsigned char *packedrgb,
int width, int height)
{
GdkImlibImage *imlibimage;
GdkPixmap *pmap;
GdkBitmap *mask;
/* sanity checks ... */
assert(pixmap != NULL);
assert(packedrgb != NULL);
assert(width >= 0);
assert(height >= 0);
/* create an image from packed RGB data */
imlibimage = gdk_imlib_create_image_from_data(packedrgb,
NULL,
width,
height);
/* render it */
gdk_imlib_render(imlibimage, width, height);
/* get pmap and mask to update pixmap */
pmap = gdk_imlib_move_image(imlibimage);
mask = gdk_imlib_move_mask(imlibimage);
/* update pixmap */
gtk_pixmap_set(GTK_PIXMAP(pixmap), pmap, mask);
/* cleanup imlib stuff */
gdk_imlib_kill_image(imlibimage);
gdk_imlib_free_pixmap(pmap);
gdk_imlib_free_bitmap(mask);
}
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2785859 Fax: +31-15-2781843 Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]