My problem is with memory usage: it continually gobbles RAM. Even if I comment outuse Text::Ngram qw( ngram_counts ); use ... use ... my $db = "/home/db/repository/megalith.db"; my $ngram_width = 5; my %protein_search_hash; unlink $db; tie %protein_search_hash, 'MLDBM', -Filename => $db, -Flags => DB_CREATE | DB_INIT_LO +CK or die "Cannot open database '$db: $!\n"; open FILE, "<test_data_2MB.txt" or die "Failed to load test_data: $!\n"; my $fasta_sequence = do { local $/; <FILE> }; close(FILE); # Precompile regex for speed my $regex = qr/>([\S]*)\s*.*\s([A-Za-z\s]+)/; my $regex_d = qr/^>[\S]*\s*.*\s[A-Za-z\s]+/; # PARSE $fasta_sequence and split header from the sequence while( $fasta_sequence =~ m/$regex/igm ) { my $sequence = $2; my $header = $1; $sequence =~ tr/[\r|\n]//d; # delete all line breaks # generate n-grams my $ngram_href= ngram_counts($sequence, $ngram_width); $protein_search_hash{$header} = $ngram_href; } ... ... ...
...it still eats the same amount of RAM each time. However, I have narrowed it down to$protein_search_hash{$header} = $ngram_href;
...as being the problem. I've tried undef and putting it in a subroutine but nothing stops the insatiable thirst for RAM. Currently, I'm limited to processing data files under 13MB (anything higher and I'm out of RAM and into swap). If I comment out the above line, RAM usage flatlines like I would expect. Why isn't '$ngram_href' being overwritten each iteration through and the old value being GC'd? Monks, what am I missing here? Any help would be much appreciated!my $ngram_href= ngram_counts($sequence, $ngram_width);
In reply to Memory Growth Problem by Robgunn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |