gpt4 book ai didi

javascript - NodeJS- fatal error : CALL_AND_RETRY_LAST Allocation failed

转载 作者:太空宇宙 更新时间:2023-11-04 01:55:28 25 4
gpt4 key购买 nike

我遇到了这个问题...我使用的是 Windows 7 和 Chrome。

我尝试过这个解决方案: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

但没有成功。

还尝试了其他方法: Devextreme : FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

但我找不到该文件,就像它不存在一样。

  1. 我正在尝试做this教程。

  2. 我正在执行的代码是这样的:

var http = require("http"),
fs = require("fs");

http.createServer(function(req, res){

fs.readFile("./index_ASYNC.html", function(err, html){
var i=0;

while(true) {
i++;
res.write(i+""); // Envía respuestas al navegador.
}

// res.writeHead(200,{"Content-Type":"text/html"});
res.end();
});

}).listen(8080);
  • 我使用node Hola_html.js执行它。

  • 产生的错误:

  • <--- Last few GCs --->

    [5344:00000000002C05B0] 46772 ms: Mark-sweep 1399.5 (1427.9) -> 1399.5 (1427. 9) MB, 2231.9 / 0.0 ms allocation failure GC in old space requested [5344:00000000002C05B0] 49806 ms: Mark-sweep 1399.5 (1427.9) -> 1399.5 (1426. 9) MB, 2583.4 / 0.0 ms last resort GC in old space requested [5344:00000000002C05B0] 52394 ms: Mark-sweep 1399.5 (1426.9) -> 1399.5 (1426. 9) MB, 2588.3 / 0.0 ms last resort GC in old space requested

    <--- JS stacktrace --->

    ==== JS stack trace =========================================

    Security context: 0000028BF5325EE1 1: _send [_http_outgoing.js:~216] [pc=0000002FDD52590C](this=000000B79B184D2 1 ,data=000003BB18D85CB1 ,encoding=0000010C6FF02201 ,callback=0000010C6FF02201 < null>) 2: /* anonymous */ [C:\Leo\Prodigios\CursoNodeJS\4-encabezados\hola_html_ASY NC_v2.js:~10] [pc=0000002FDD5131F2](this=00000191E280BE21

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memo ry

  • 我必须补充一点,我尝试了在互联网上找到的第二个选项 ( Devextreme : FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory ),但没有成功。
  • 最佳答案

    显然这个例子会导致内存泄漏,这一行是导致它的原因:

    while(true) {    
    i++;
    res.write(i+""); // Envía respuestas al navegador.
    }

    您在这里循环无限递增 i 并多次写入输出(您应该只写入一次)。

    垃圾收集器没有时间来处理这个问题,你的 RAM 很快就会达到极限

    我不知道该视频中的语言,但我相信作者对这种方法发出了警告。

    示例应用程序可能如下所示:

    var http = require('http'); // import module
    http.createServer(function (req, res) { // create http server
    // create header to let browser know what content you are trying to send
    res.writeHead(200, {'Content-Type': 'text/plain'});
    // write string to client
    res.write('Hello World!');
    // end the request
    res.end();
    }).listen(8080); // listen to requests on http://localhost:8080

    我在你的教程中看到有更复杂的示例可以使用,比如说 4:25

    关于javascript - NodeJS- fatal error : CALL_AND_RETRY_LAST Allocation failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48147100/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com