Weird behavior - memory gets sucked up




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



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