[9674] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] Weird behavior - memory gets sucked up

daemon@ATHENA.MIT.EDU (Eric Harlow)
Fri Oct 30 10:49:08 1998

Date: Fri, 30 Oct 1998 07:50:23 -0800 (PST)
From: Eric Harlow <linuxgeek@yahoo.com>
To: gtk-list@redhat.com
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com


I'm writing a sample program that reads in apache log files for
analysis.  As part of that, I display a progress bar in case they have
these really *large* log files that they're trying to view to let them
know how far the read is going. 

To get this to update, I put in a couple of lines after I update the
progress bar:

    while (gtk_events_pending ()) {
        gtk_main_iteration ();
    }

While this updated my progress bar nicely, my memory footprint (which
was 4.3% of memory) ballooned to 15% of available memory.  Reparsing
the file and displaying the progress bar again caused my memory
consumption to jump to 25% of available memory. 

If I comment out those lines (see above) my memory footprint stays low. 

For now, I got around the program by putting in some lines like:

    /* --- pvalue is 0 to 1.0 float value --- */
    pct = pvalue * 100;

    if (lastPct != pct) {

        /* --- Update progress bar --- */
        gtk_progress_bar_update (
                          GTK_PROGRESS_BAR (pbar), 
                          pvalue);

        while (gtk_events_pending ()) {
            gtk_main_iteration ();
        }
        lastPct = pct;
    }

I did this when I found out how slow it was to call
gtk_progress_bar_update every iteration.  (Probably because if I have
a 100000 line log file, the damn progress bar is updating after every
call - me thinks the code in the progress bar should be changed from a
delta floating point comparision to an integer comparision.  Do you
really want to update the progress bar if the % has changed from
.1000000 to .1000001?  But I digress.)

Putting the code in a block that gets called 100 times  (as opposed to
10000 or so) seemed to significantly reduce the memory footprint.  The
gtk_progress_bar_update function needs to be called in the loop to
cause the leak.  For my really large log file, the old code ends up
acting like an MS app - sucking down 90% of memory and causing disk
swap. 

I've gotten around it, but don't know why it occurs.  Explanations
appreciated. I'm using gtk 1.0.4

 -Eric
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post