[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] probable memory leak using chop/split



Hi all, you might want to try this one and tell me if I'm crazy:

I'm running out of memory with the following simple program:

while (<>) {
        $lineCount++;
        if ($lineCount % 10 == 0) {
                print "$lineCount\n";
        }
        chop;
        @fields = split(/\t/);

}

I admit that the input that causes this problem is a bit peculiar. When
exporting spread sheet data from Excel, one might get many thousands of
lines, even though the only data is in the first 100 or so. The rest of the
lines contain many empty fields. Here's a snippet that makes test data
that causes the above mentioned out-of-memory problem:

open (OUT, ">test.data") || die ("yipes");
for ($i = 0; $i < 2500; $i++) {
        for ($j = 0; $j < 30; $j++) {
                print OUT "\t";
        }
        print OUT "\n";
}
close OUT;
print "Done\n";

Save the first program as a droplet, then drop "test.data" on it. On my
system, long about line 1100 or so, I get "out of memory". Varying the
number of empty fields will cause the memory to leak away faster or
slower.

The problem appears to be with the combination of the chop and split.
If you comment out the chop (or chomp), everything works.
Since the basic split will remove all empty fields, I assume that they're
hanging around somewhere.

I'm running 5.07r1m on a Performa 6115 (power pc). I have not changed MacPerl's
memory partition.

Thanks for a great program!


Fred Toth
ftoth@synernet.com