How to deal with a possible Memory Leak when using GdkPixMap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to deal with a possible Memory Leak when using GdkPixMap

Michal Porzuczek
Hi,

I have written a program pretty much by re-adjusting the scribble
example from the GTK Tutorial, instead of creating my own PixMap in
the configure_event I called the following function which creates a
pixmap from file:

GdkPixmap* gdk_pixmap_new_from_file( const char *filename )
{
        GdkPixbuf *pixbuf;
        GdkPixmap *pixmap;

        pixbuf = gdk_pixbuf_new_from_file( filename,NULL);
        if (!pixbuf)
        {
                g_print( "Could not load `%s'!\n", filename );
                return NULL;
        }

        gdk_pixbuf_render_pixmap_and_mask( pixbuf, &pixmap, NULL, 1 );

        gdk_pixbuf_unref( pixbuf );

        return pixmap;
}

I have this function called everytime expose_event is called because
the file that will get displayed in the drawing area keeps getting
updated by another program.

As the program runs and I move the mouse around the screen making
marks my CPU activity jumps dramatically and the virtual memory
occupied by the X-Window seems to be increasing on like an exponential
level.

I am wondering if maybe there is a call that can free up some of the
space as I recall the gdk_pixmap_new_from_file in the expose_event
callback. Or some other solution to mitigate this problem

thanks a lot,

Michal
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

RE: How to deal with a possible Memory Leak when using GdkPixMap

Freddie Unpenstein

> I have written a program pretty much by re-adjusting the scribble
> example from the GTK Tutorial, instead of creating my own PixMap in
> the configure_event I called the following function which creates a
> pixmap from file:

>        pixbuf = gdk_pixbuf_new_from_file(filename,NULL);

There's yor CPU hog...!


> I have this function called everytime expose_event is called
> because the file that will get displayed in the drawing area keeps
> getting updated by another program.

Are you sure you need to reload the image EVERY time your expose event gets called?

At the very least, user stat() to check whether the last modified time on the image file has been changed, and only re-load it when neccesary.

You may also find, though, that part of the image gets updated with the new image, while part of it remains the old one (unles you're updating the entire thing every expose event, which itself would be a CPU hog).


> As the program runs and I move the mouse around the screen making
> marks my CPU activity jumps dramatically and the virtual memory
> occupied by the X-Window seems to be increasing on like an
> exponential level.

Making a mark shouldn't be too taxing...  Unless, as I said, you're updating the entire drawing area each time.  In either case, you should only be updating the smallest part of the drawing area you need to.


As far as updating the background image is concerned, I'd most definately do that from a timer, instead of from the expose event.  Every couple of seconds, or several times a second, or whatever, check to see if the file has changed (date and size), and if so, re-load the image and refresh the entire drawing area (which causes a full expose event).


Fredderic

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list