Memory usage



Dear all,

After noticing that my application appeared to be gradually consuming memory
over a long period of time, I created a simple test program based on the
"label" example to investigate it.

The program is attached to this email, but basically creates a label and
then repeatedly changes the text in it (10 times a second).  It seems to
consume memory at roughly 3Mb per hour (or approximately 88 bytes per label
change on average), as shown in "top".

All I'm doing is calling gtk_label_set_text() in a timer callback function
(installed with g_timeout_add()), but gradually the memory gets used up.

Am I missing something?  I know the FAQ says that things are cached within
GLIB etc. even when freed and that you shouldn't rely on "top" for memory
debugging, but does this really explain the memory usage here?

I'm using GTK V1.3.9 at the moment.  I tried it with V1.2.8 and that's
fine - the memory stays constant.

I've tried following through the code from gtk_label_set_text() and
basically got down to a call to gdk_window_invalide_rect() which if I
commented out then the memory stayed stable (but the label obviously wasn't
updated).  I got confused at this point by all the rectangle
allocation/freeing actions such as gdk_region_rectangle() and
gdk_region_destroy().  The route through the code seemed to be ...

gtk_label_set_text()
gtk_label_recalculate()
gtk_widget_queue_resize()
gtk_widget_queue_clear()
gtk_widget_queue_clear_area()
gdk_window_invalidate_rect()
gdk_region_rectangle() / gdk_region_destroy() etc.

I expect I'm being stupid (in which case please point out my mistake!), but
if not I'd be grateful if anyone can explain what's going on and how I can
stop the memory being used up.

Thanks in advance,
Richard.


Attachment: label.c
Description: Binary data



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