我的perl程序泄漏内存的地方?

时间:2013-11-24 08:38:47

标签: perl memory-leaks

我正在将2个具有1000万行(1行最多200个字符)的地图传递给下面的函数。此功能导致内存错误。我是perl的新手,有人可以帮助我找出导致内存泄漏的地方。

sub createDataFile{
my($rowIdToBatchIdMap_ref, $batchIdToNFSFileNameMap_ref, $reportDataCsvFileName, $reportDataCsvFileNameToCreate) = @_;

open FILETOREAD, $reportDataCsvFileName or die "unable to open a  file $reportDataCsvFileName for reading reports data. $!";
open FILETOWRITE, ">".$reportDataCsvFileNameToCreate or die "unable to open a  file $reportDataCsvFileNameToCreate for writing reports data. $!";

my $countOfReportHavingNullBatchId = 0;
my $countOfMissingBatchIdInBatchTable = 0;
my $countOfMissingTransRefNoInReportTable = 0;

#reading file line by line
while(<FILETOREAD>){

    my @fields = split( ',', $_ );
    my $reportRowId = $fields[0];

    if(! exists($rowIdToBatchIdMap_ref->{$reportRowId})){
        $logger->log(Debug  => "key do not exist in rowIdToBatchIdMap for row id $reportRowId");
        my $replacedLine = $fields[0]. ",," . $fields[1];
        print FILETOWRITE $replacedLine;
        $countOfReportHavingNullBatchId++;
        next;
    } else {
        my $batchId = $rowIdToBatchIdMap_ref->{$reportRowId};
        $batchId = trim($batchId);

        if(! exists($batchIdToNFSFileNameMap_ref->{$batchId})){
          $logger->log(Debug  => "key do not exist in batchIdToNFSFileNameMap_ref for batch id $batchId");
          my $replacedLine = $fields[0]. ",," . $fields[1];
          print FILETOWRITE $replacedLine;
          $countOfMissingBatchIdInBatchTable++;
        } else {

            my $xmlFileName = $batchIdToNFSFileNameMap_ref->{$batchId};
            my $replacedLine = $fields[0]. "," . $xmlFileName . "," . $fields[1];
            print FILETOWRITE $replacedLine;    
        }

    }

} #end of while

$logger->log(Info => "No of reports having null batch id in REPORT_DATA table is $countOfReportHavingNullBatchId");
$logger->log(Info => "No of reports whose batch id is not present in BATCH table is $countOfMissingBatchIdInBatchTable");
close(FILETOREAD);
close(FILETOWRITE);
}

1 个答案:

答案 0 :(得分:0)

我找出了根本原因。这是由于我使用Dumper函数在调用上述函数之前将日志文件中的地图内容转储。我删除了该行,现在不再出现内存不足错误。