1

when i am writing recursive program which reads 70mb file line by line and processes.I am using recursion to process the line .here is my code

function readFile(response, postData){

    var instream = fs.createReadStream('filePath');
    var datmap={};
    var rl = readline.createInterface({
        input: instream,
        output: outstream,
        terminal: false
    });

    rl.on('line', function(line) {
        hirarchyFun(datmap,line); 
    });
}

hirarchyFun=function(map,line){
    var key;
    if(line.indexOf(",") != -1){
        key=line.substring(0,line.indexOf(","));
        var subLine=line.substring((key.length+1));
        var internMap=map[key];
        if(typeof internMap == 'undefined'){
            internMap={};
        }
        var value=hirarchyFun(internMap,subLine);
        map[key]=value;
        return map;
    }else{
        return line;
    }
}

when I am reading file which is about 70mb giving error as

FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory

but its working fine for file about 700kb. can any one help on this issue??

Ivo
  • 3,481
  • 1
  • 25
  • 29
sri_sankl
  • 223
  • 4
  • 13
  • why dont you try to add a callback on hirachyFun function and use it in asynchronously . – Vivek Bajpai Sep 20 '13 at 08:38
  • I am getting the same when I was trying primes below 1 Bn. – Siva Tumma Dec 31 '13 at 11:20
  • Possible duplicate of [FATAL ERROR: CALL\_AND\_RETRY\_LAST Allocation failed - process out of memory](https://stackoverflow.com/questions/26094420/fatal-error-call-and-retry-last-allocation-failed-process-out-of-memory) – Paul Sweatte Sep 12 '17 at 16:06

0 Answers0