Skip to content

Silly program or memory leak? #2970

Description

@fivdi

Although the following program is a little silly, it results in a "process out of memory" with Node.js v4.0.0 on a Linux system after a few minutes of execution.

while (true) {
  console.log("Hello, World!");
}

Here's the output:

...
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!

<--- Last few GCs --->

  710976 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15343.7 / 0 ms [allocation failure] [GC in old space requested].
  726188 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15212.6 / 0 ms [allocation failure] [GC in old space requested].
  741831 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15642.7 / 0 ms [last resort gc].
  757723 ms: Mark-sweep 698.3 (737.7) -> 698.3 (737.7) MB, 15892.2 / 0 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0x37c258b9 <JS Object>
    1: nextTick [node.js:~465] [pc=0x341fac9c] (this=0x37c7f939 <a process with map 0x563136b1>,callback=0x3e7bf5e1 <JS Function afterWrite (SharedFunctionInfo 0x3e777679)>)
    2: arguments adaptor frame: 5->1
    3: onwrite(aka onwrite) [_stream_writable.js:~314] [pc=0x341f3f50] (this=0x37c08099 <undefined>,stream=0x3e7bf6b1 <a WriteStream with map 0x56322bc9>,er=0x37c08099 <undefined>)
    4: _w...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Aborted

Activity

  1. ChALkeR commented on Sep 20, 2015

    @ChALkeR
    Member

    Dupe of #1741.

  2. added
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    memoryIssues and PRs related to Node.js memory management or memory footprint.
    on Sep 20, 2015
  3. ChALkeR commented on Sep 20, 2015

    @ChALkeR
    Member

    Short answer: console output is buffered and async. Your console is slower then the script, and the buffer isn't limited by anything except for the global memory limit. So, it fills up the buffer and dies.
    More info at #1741.

    For anyone picky enough: by «buffer» I mean the implicit buffer that is actually the async operation queue.

  4. fivdi commented on Sep 20, 2015

    @fivdi
    Author

    @ChALkeR thanks for the short answer, it's easier to understand than the long one :)

  5. ChALkeR commented on Sep 20, 2015

    @ChALkeR
    Member

    @fivdi You could try to redirect the output to a file. It works for me as a work-around.
    But this shouldn't be an issue if you are not firing writes to console faster then it could process them.

  6. added
    consoleIssues and PRs related to the console subsystem.
    on Sep 20, 2015
  7. fivdi commented on Sep 20, 2015

    @fivdi
    Author

    @ChALkeR thanks again. Redirecting the output to a file works around the issue for me too and is fine for what I want to achieve.

  8. added a commit that references this issue on May 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    consoleIssues and PRs related to the console subsystem.duplicateIssues and PRs that are duplicates of other issues or PRs.memoryIssues and PRs related to Node.js memory management or memory footprint.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions