I wrote one script to read three files and calculate some values after taking some data from that files. The file sizes are ~30Gb, ~25Gb and 1Gb. All the data in these files are tab separated. I am running the program in a double hex core 24 theaded server having 192 Gb ram. Now script is serving the purpose in quite nice time (~ 30 mins) with a memory foot print of <= 7Gb, whereas using top command I can see it is taking ~40Gb. But the problem I am facing is, it is not at all clearing the used memory after execution. I need to run it for several set of files eg (48 sets) even if I want to run in batch process. After 4-5 run I am not getting any of free memory to use. What are the possible ways that can serve me the purpose.

$in1=$ARGV[0]; $in2=$ARGV[1]; $in3=$ARGV[2]; $out1=$ARGV[3]; if (scalar @ARGV != 4){ die " Wrong command\n\n"; } open(OUT,">$outfile"); open (IN1,"$in1"); while (<IN1>){ if ($_ !~ /^\expr/ && $_ !~ /^expr/){ if ($_ =~ /expr/){ if(cond){$some_count++;} } } } close IN1; undef (@_);undef ($_);undef ($in1); $per_reads_aligned = ($reads_aligned/$total_reads)*100; my %hash1 = (); open (IN2,"$in2"); while (<IN2>){ chomp ($_); $hash1{$_} = 1; } $count2=keys(%hash1); close IN2; undef ($in2); undef (@_); undef ($_); open (IN3,"$in3"); while (<IN3>){ if ($_ =~ /expr/){ $var1=$1;$var2=$2;$var3=$3;$var4=$4; if($var1 ne "N" && $var1 ne "S"){ $hhkey1=$var2."_".$var4; if (exists $hash1{$hhkey1}){ $count3++; if($var3 >= 5){$count5++;} if($var3 >= 10){$count6++;} if($var3 >= 15){$count7++;} if($var3 >= 20){$count8++;} } } } } close IN3; undef ($in3); undef (@_); undef ($_); undef (%hash1); ## Some calculation and print to outfile close OUT;

In reply to How to free memory used by previous program? by sourav8888

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.