FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory in preprocessing my js fiels

Deadly 提交于 2020-01-13 06:55:08

问题


i am trying to preprocess my js files for each platform and beautify it using my js-preprocess.js .i am able to process upto 153 files.if the number of files increase,the console is showing the following error! FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory Please help me to resolve this! here is my one code snippet for the main job!

fs.readdir(inputdir,function(err,files) {
     console.time('PreProcessingJStime')
    files.forEach(function(file) {
        if (file.indexOf(".js") != -1) {
            console.log('PreProcessing JS File : '+file);
            fs.writeFile(outputdir+"/"+file,beautify.js_beautify(preprocess(fs.readFileSync(inputdir+"/"+file,'utf-8'),defines).join('\n'),{preserve_newlines:false}));
        }
    },this);
    console.timeEnd('PreProcessingJStime')
})

Thanks in advance :)


回答1:


You're using fs.writeFile, which is asynchronous. This means you're writing to all files at the same time, and all the data needed for this is buffered in memory. If you change it to fs.writeFileSync, then it finishes with one file before moving on to the next one, and all the data concerning previous files becomes garbage, so the garbage collector will get it when it needs to.



来源:https://stackoverflow.com/questions/25154423/fatal-error-call-and-retry-2-allocation-failed-process-out-of-memory-in-prepr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!