memleak (or not) with X, further details
- From: Wolfgang Sourdeau <wolfgang ultim net>
- To: gtk-devel-list gnome org
- Subject: memleak (or not) with X, further details
- Date: Sat, 16 Dec 2000 03:10:11 -0500
Hi,
A few weeks ago, I mentionned that I had found a sort of memleak with X.
I have tried to investigate this tonight without very representative results.
The way this situation can be reproduced is by taking any basic image viewer and
display each time a different image.
Normally the RSS size reported in /proc/<pid of X>/status will increase of
a couple of 10Kb each time. However, when displayed the same image, this
does not happen.
I don't understand this difference. This is probably not that serious after all.
But also I am not an X internals wizard so you might have a better answer
to this than me.
I enclose a small utility which can serve as a basic image viewer. Don't
pay too much attention to the code, this is a program derived from another
utility I have written a month ago, which I slightly adapted for this
particular case. Requires GTK+ and gdkpixbuf.
Wolfgang
-- 
A chicken is an egg's way of producing more eggs.
/* (derived from) BAOBAB - gdkpb_set_bg - http://baobab.insu.com
 *
 * Copyright (C) 2000 iNsu Innovations, Inc.
 *
 * Author: Wolfgang Sourdeau <wolfgang iNsu COM>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#define VERSION "0.XX"
#define PACKAGE "gdkpb_test"
#define print_usage() printf ("usage: " PACKAGE " file\n")
GdkPixmap*
render (GdkPixbuf *pixbuf, GdkWindow *target_win, GdkGC *gc,
	gint width, gint height)
{
  GdkPixmap *back_pix;
  GdkPixmap *pixmap;
  GdkBitmap *bitmap;
  back_pix = gdk_pixmap_new (target_win, width, height, -1);
  gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap,
				     GDK_PIXBUF_ALPHA_BILEVEL);
  gdk_draw_pixmap (back_pix, gc, pixmap,
		   0, 0, 1, 1,
		   width, height);
  gdk_pixmap_unref (pixmap);
  if (bitmap)
    gdk_bitmap_unref (bitmap);
  return back_pix;
}
GtkWidget*
create_window (gint width, gint height)
{
  GtkWidget *new_win;
  new_win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (new_win),
			       width + 2, height + 2);
  gtk_signal_connect (GTK_OBJECT (new_win), "destroy", gtk_main_quit, NULL);
  gtk_widget_show (new_win);
  return new_win;
}
void
render_pixbuf (GdkPixbuf *pixbuf)
{
  GdkPixmap *back_pix;
  GtkWidget *gtk_win, *gtk_pmap;
  GdkWindow *target_win;
  GdkGC *gc;
  gint pix_width, pix_height;
  gint err_code;
  pix_width = gdk_pixbuf_get_width (pixbuf);
  pix_height = gdk_pixbuf_get_height (pixbuf);
  gtk_win = create_window (pix_width, pix_height);
  target_win = gtk_win->window;
  gc = gtk_win->style->bg_gc [GTK_STATE_NORMAL];
  back_pix = render (pixbuf, target_win, gc, pix_width, pix_height);
  gtk_pmap = gtk_pixmap_new (back_pix, NULL);
  gtk_container_add (GTK_CONTAINER (gtk_win), gtk_pmap);
  gtk_widget_show (gtk_pmap);
  gdk_draw_pixmap (target_win, gc, back_pix, 
    		   0, 0, 1, 1,
    		   pix_width, pix_height);
  gdk_window_set_back_pixmap (target_win, back_pix, FALSE);
}
gint
display_image (char *filename)
{
  gint err_code;
  GdkPixbuf *pixbuf;
  pixbuf = gdk_pixbuf_new_from_file (filename);
  if (pixbuf)
    {
      render_pixbuf (pixbuf);
      err_code = 0;
    }
  else
    err_code = -1;
  return err_code;
}
int
main (int argc, char *argv[])
{
  GdkColormap *cmap;
  int c, arg_r, err_code, do_nothing;
  char *filename;
  gtk_init (&argc, &argv);
  if (argv [1]) 
    {
      err_code = display_image (argv[1]);
      if (!err_code)
	gtk_main ();
      else
	print_usage ();
    }
  else
    print_usage ();
  return err_code;
}
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]