gdkpixmap, pixbuf and memory leaking - includes example to use drawing area as well...

From: Date: Mon, 31 Dec 2001 08:53:45 +0000
Subject: gdkpixmap, pixbuf and memory leaking - includes example to use drawing area as well...
Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-945@lists.php.net to get a copy of this message
trying to get pixbuf/drawing area etc. to work.. The program is part of phpmole - it allows you to browse directories - look at the images (in a clist), - press on them , see a full size version in a drawing area - rotate them (using the imagick extension) - scale them (using the imagick extension) - drag and drop them into the gtkhtml editor. (or upload them to a midgard server) It's pretty much there, however the image display is a bit memory hungry, each time I display an image it increases the memory consumtion - eg. a directory with 2 images. just view one, then the other, and repeat process basically keeps using up memory - at infinitum.... Any ideas where this is leaking would be nice ... - it could be the pixbuf extension?, - or just the inability to free the pixmap.. below is the code for reference The way I got it to work...... Application loads up glade file with a 'scrolledwindow' ($this->drawing_area_holder) where the gtkdrawingarea goes. it then adds the drawing area. eg. function make_drawing_area($x,$y) {
              debug_echo("recreating drawing area");
       $this->drawing_area = &new GtkDrawingArea();
       $this->drawing_area->size($x,$y);
       $this->drawing_area_holder->add_with_viewport($this->drawing_area);
       $this->drawing_area->connect("configure_event", array(&$this, "drawing_area_configure_event"));
       $this->drawing_area->connect("expose_event",  array(&$this, "drawing_area_redraw_event"));
       $this->drawing_area->show();     }
   at the start it just draws a rectangle in the drawing area on configure event..
function drawing_area_configure_event($widget, $event) {
       // set up the pixmap that we use to draw to.
       // this is a copy from scribble! in tests!
       debug_echo("drawing_area_configure");
       if (!$this->drawing_area_pixmap) {
           $this->drawing_area_pixmap = &new GdkPixmap($widget->window,
                   $widget->allocation->width,
                   $widget->allocation->height,
                   -1);
                   debug_echo("drawing_area_configure_event - create pixmap");
                             debug_echo("drawing_area_configure_event - draw rectangle");                           gdk::draw_rectangle($this->drawing_area_pixmap,
                 $widget->style->white_gc,
true, 0, 0, $widget->allocation->width, $widget->allocation->height);
       }
return true; } which appears when the expose event happens eg. (really its a redraw event - so I named it that way :) function drawing_area_redraw_event($widget, $event) {
       // this handles redraw events - basically repastes the
       // drawing_area_pixmap back onto the drawing area.
       debug_echo("drawing_expose");
gdk::draw_pixmap($widget->window, $widget->style->fg_gc[$widget->state], $this->drawing_area_pixmap, $event->area->x, $event->area->y, $event->area->x, $event->area->y, $event->area->width, $event->area->height); return false; } when the user clicks on an image in the browser, $pixbuf = GdkPixbuf::new_from_file($localfile);
        if (!$pixbuf) return;
       debug_echo("got" . serialize($pixbuf));
                  $x = $pixbuf->get_width();
      $y = $pixbuf->get_height();
            /* this may not actually release the memory */
      unset($this->drawing_area_pixmap);
                  $this->drawing_area_pixmap = &new GdkPixmap($this->drawing_area->window,
                        $x,
$y,
                   -1);
     $this->drawing_area->size($x,$y);
      debug_echo("rendering $x, $y");
       $pixbuf->render_to_drawable($this->drawing_area_pixmap,
$this->drawing_area->style->fg_gc[GTK_STATE_NORMAL], 0, 0, 0, 0, $x, $y, GDK_RGB_DITHER_NORMAL, $x, $y); // hey this is the clever bit - it tells the drawing area to refresh the rectangle 0,0,x,y
     $this->drawing_area->draw(new GdkRectangle(0, 0,
$x, $y));
      $pixbuf->unref();
     


« previous php.gtk.general (#945) next »