Fw: [PHP-GTK] gdkpixmap, pixbuf and memory leaking - includes example to use drawing area as well...
| From: | Steph | Date: | Mon, 31 Dec 2001 14:16:06 +0000 |
| Subject: | Fw: [PHP-GTK] 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-949@lists.php.net to get a copy of this message | ||
I just looked thru and found we don't have gdk_pixmap_unref exposed. But Andrei had to
implement some new stuff in php-gtk to get the scribble port to work at all .. & he
implemented pixmap_new as part of that burst of implementation. If you look through the gdk
overrides you'll see that he's written gdk_pixmap_unref into all the pre-existing pixmap
create functions, and that they all contain pixmap_new ... so it looks like someone's going to
have to do a bit of restructuring, i.e. write the unref function into pixmap_new and then eliminate
it from the other four.
Just a guess. & I'd be happier if Andrei were to confirm that.
----- Original Message -----
From: "Steph" <Steph.Fox@btinternet.com>
To: "Alan Knowles" <alan@akbkhome.com>
Sent: Monday, December 31, 2001 1:50 PM
Subject: Re: [PHP-GTK] gdkpixmap, pixbuf and memory leaking - includes example to use drawing area
as well...
In the original 'scribble' the opening line when creating a new backing pixmap went
if (pixmap)
gdk_pixmap_unref(pixmap);
? - can't test this, m8, bleedin' doze.
----- Original Message -----
From: "Alan Knowles" <alan@akbkhome.com>
To: <php-gtk-general@lists.php.net>
Sent: Monday, December 31, 2001 8:53 AM
Subject: [PHP-GTK] gdkpixmap, pixbuf and memory leaking - includes example to use drawing area as
well...
> 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();
>
>
>
>
>
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, e-mail: php-gtk-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-gtk-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>