致命错误:CALL_AND_RETRY_2分配失败 - 在预处理我的js fiels时处理内存不足 [英] FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory in preprocessing my js fiels

查看:103
本文介绍了致命错误:CALL_AND_RETRY_2分配失败 - 在预处理我的js fiels时处理内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为每个平台预处理我的js文件并使用我的js-preprocess.js美化它。我能够处理多达153个文件。如果文件数量增加,控制台显示以下错误!
致命错误:CALL_AND_RETRY_2分配失败 - 处理内存不足
请帮我解决此问题!
这是我主要工作的一个代码片段!

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')
})

提前致谢:)

推荐答案

你正在使用 fs.writeFile ,这是异步的。这意味着您同时写入所有文件,并且所需的所有数据都缓存在内存中。如果你将它改为 fs.writeFileSync ,那么它会在转到下一个文件之前完成一个文件,并且所有与之前文件有关的数据都会变成垃圾,所以垃圾收集器会在需要的时候得到它。

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.

这篇关于致命错误:CALL_AND_RETRY_2分配失败 - 在预处理我的js fiels时处理内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆