Hi all, looking for some help :)

I have a script that has to parse and generate stats from some HUGE logfiles. It's written so that I keep bare min content of logfile in memory for least amount of time.

The problem is that garbage collection doesn't seem to happen, after the array holding the log data goes out of scope.

Specifially, I watch the mem usage grow on read by looking via top, but the mem usage never decreases once the array is out of scope, or even if i undef it in debugger. It's about 20M min of mem usage post read, so a drop should be noticeable

I'm SURE there are no references to it (I don't make any, i just count different items inside the lines), and even tried making it an object to see if garbage collection would do its thing, but that didn't help.

I'm doing this via ssh and I have also tried undefing the $ssh object after one file read, to no effect (memory usage still stays high)

I'm doing something like:

foreach my $log ( @log_names ) { my ($stdout, $stderr, $exit) = $ssh->cmd( "cat $log " ) my @logdata = split /\n/, $stdout; undef $stdout; while ( my $line = pop @logdata ) { # parse/collect stats on $line } }

I'm stumped and it's chewing up too much memory after I get through several log files, because it's never freed.

thanks for any suggestions or help!


In reply to garbage collection not happening? by infidel2112

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.