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

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).


Join Excite! -
The most personalized portal on the Web!

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]