1

I am having this problem... I am using Windows 7 and Chrome.

I have tried this solution: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

But didn't work.

Also tried this other: Devextreme : FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

But I cannot find that file, like if it doesn't exist.

  1. I am trying to do this tutorial.

  2. The code I am executing is this:

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);
  1. I execute it using node hola_html.js.

  2. The resulting error:

<--- 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

  1. I must add, I tried the second option I found on Internet (Devextreme : FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory) but it didn't work.
2
  • You need to provide example what you've tried, the exact error, and maybe how to reproduce Commented Jan 8, 2018 at 9:45
  • Edited :D . Thanks Commented Jan 8, 2018 at 20:58

1 Answer 1

0

Obviously this example will cause memory leak, this line is causing it:

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

You are looping here infinitely incrementing i and writing to output multiple times (you should only write once).

There is no time for garbage collector to pick this up, and your RAM soon reaches its limit

I don't know language in this video but I believe author was warning about this approach.

Example application could look like this:

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

I see in your tutorial there are more complex examples that will work, let's say at 4:25

Sign up to request clarification or add additional context in comments.

3 Comments

I can understand that making an infinite loop will make program to non stop... because is "infinite" xD . But I wonder WHY he does it then... I will ask youtuber why... I didn't ask him because looks like he doesn't answer much... Thank you very much anyways. If he doesn't answer me in 1 week I will give your answer like valid.
There is no time for garbage collector to pick this up. I feel this is an incorrect statement. GC doesn't wait for main thread to pause (AFAIK) Your issue might be around this - github.com/nodejs/node/issues/2970#issuecomment-141819829
There is no console here though. I didn't say it waits for event loop to be empty, too. Application overflows so quickly that there is no way for GC to pick this up, that's all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.