ezekiel has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have included the guts of a script I have written that basically counts the frequency of alphabetic characters in a series of strings. It runs fine except, it has a memory leak, gradually using up memory until the machine expires. I have tried undef-ing everything in sight but still the problem occurs. Either I have missed something, in which case I would be grateful if a fresh pair of eyes could point it out, or perhaps there is a leak in the DBI module? Thanks for your help.
open (OUTPUT, ">>./output.txt") or die "Cannot open the output file: $ +!"; foreach my $id (@ids) { my $sth = $dbh->prepare("select long_string from my_table where id +=?"); $sth->execute($id); my $long_string = $sth->fetchrow_array(); $sth->finish(); undef($sth); my %count; my @letters = split("", $long_string); foreach my $letter (@letters) { $count{$letter}++; } undef(@letters); undef($long_string); # Print out the counts for each string print OUTPUT "$id\t" . ($count{A} || 0) . "\t" . ($count{B} || 0) . "\t" . ($count{C} || 0) . "\t" . ($count{D} || 0) . "\t" . ($count{E} || 0) . "\t" . ($count{F} || 0) . "\t" . ($count{G} || 0) . "\t" . ($count{H} || 0) . "\t" . ($count{I} || 0) . "\t" . ($count{J} || 0) . "\t" . ($count{K} || 0) . "\t" . ($count{L} || 0) . "\t" . ($count{M} || 0) . "\t" . ($count{N} || 0) . "\t" . ($count{O} || 0) . "\t" . ($count{P} || 0) . "\t" . ($count{Q} || 0) . "\t" . ($count{R} || 0) . "\t" . ($count{S} || 0) . "\t" . ($count{T} || 0) . "\t" . ($count{U} || 0) . "\t" . ($count{V} || 0) . "\t" . ($count{W} || 0) . "\t" . ($count{X} || 0) . "\t" . ($count{Y} || 0) . "\t" . ($count{Z} || 0) . "\n"; undef(%count); } close (OUTPUT) or die "Cannot close the output file: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Where are those memory leaks?
by jZed (Prior) on Mar 24, 2004 at 03:31 UTC | |
by ezekiel (Friar) on Mar 24, 2004 at 04:11 UTC | |
by waswas-fng (Curate) on Mar 24, 2004 at 07:03 UTC | |
|
Re: Where are those memory leaks?
by jaa (Friar) on Mar 24, 2004 at 09:26 UTC | |
|
Re: Where are those memory leaks?
by kvale (Monsignor) on Mar 24, 2004 at 04:48 UTC | |
by jZed (Prior) on Mar 24, 2004 at 04:56 UTC | |
|
Re: Where are those memory leaks?
by DrHyde (Prior) on Mar 25, 2004 at 10:05 UTC | |
|
Re: Where are those memory leaks?
by periapt (Hermit) on Mar 25, 2004 at 13:17 UTC |