Skip to content

Instantly share code, notes, and snippets.

@cloudy9101
Forked from tjunghans/node-v8-max-old-space-size.md
Last active December 23, 2020 05:51
Show Gist options
  • Save cloudy9101/23f3d8b4c82cdaab03f8a3b4710edd80 to your computer and use it in GitHub Desktop.
Save cloudy9101/23f3d8b4c82cdaab03f8a3b4710edd80 to your computer and use it in GitHub Desktop.

Revisions

  1. cloudy9101 revised this gist Dec 23, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    # Node V8 Option max-old-space-size

    ## Problem
    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed — Javascript process out of memory

    This error occurs when the memory allocated for the execution application is less than the required memory when run application.
    By default the memory limit in Node.js is 512 mb, to solve this issue you need to increasing the memory limit use command —- max-old-space-size .It can be avoid the memory limit issue.

    ## Command line

    ```
  2. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,5 @@ export NODE_OPTIONS=--max-old-space-size=8192

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
    - [memory limit in Node.js (and chrome V8)](https://stackoverflow.com/q/7193959)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
    - [Add max-old-space-size to npmrc #1783](https://github.com/nodejs/help/issues/1783)
  3. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,17 @@ node --help --v8-options | grep -B 1 -A 1 max-old-space
    > "Old space" is the biggest and most configurable section of V8's managed (aka garbage-collected) heap (i.e. where the JavaScript objects live), and the --max-old-space-size flag controls its maximum size. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
    If heap memory consumption (i.e. live objects that the GC cannot free) exceeds the limit, V8 will crash your process (for lack of alternative), so you don't want to set it too low. Of course, if you set it too high, then the additional heap usage that V8 will allow might cause your overall system to run out of memory (and either swap or kill random processes, for lack of alternative).
    In summary, on a machine with 2GB of memory I would probably set --max-old-space-size to about 1.5GB to leave some memory for other uses and avoid swapping.

    - [Source Stackoverflow](https://stackoverflow.com/a/48392705)

    ## Setting

    ```
    export NODE_OPTIONS=--max-old-space-size=8192
    ```

    ## References

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
    - [memory limit in Node.js (and chrome V8)](https://stackoverflow.com/q/7193959)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
  4. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,20 @@
    # Node V8 Option max-old-space-size

    ## Command line

    ```
    node --help --v8-options | grep -B 2 -A 2 max-old-space
    --experimental-new-space-growth-heuristic (Grow the new space based on the percentage of survivors instead of their absolute value.)
    node --help --v8-options | grep -B 1 -A 1 max-old-space
    type: bool default: false
    --max-old-space-size (max size of the old space (in Mbytes))
    type: size_t default: 0
    --initial-old-space-size (initial old space size (in Mbytes))
    ```

    > "Old space" is the biggest and most configurable section of V8's managed (aka garbage-collected) heap (i.e. where the JavaScript objects live), and the --max-old-space-size flag controls its maximum size. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
    If heap memory consumption (i.e. live objects that the GC cannot free) exceeds the limit, V8 will crash your process (for lack of alternative), so you don't want to set it too low. Of course, if you set it too high, then the additional heap usage that V8 will allow might cause your overall system to run out of memory (and either swap or kill random processes, for lack of alternative).
    In summary, on a machine with 2GB of memory I would probably set --max-old-space-size to about 1.5GB to leave some memory for other uses and avoid swapping.
    [Source Stackoverflow](https://stackoverflow.com/a/48392705)
    - [Source Stackoverflow](https://stackoverflow.com/a/48392705)

    ## References

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
  5. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,11 @@ node --help --v8-options | grep -B 2 -A 2 max-old-space
    --initial-old-space-size (initial old space size (in Mbytes))
    ```

    > "Old space" is the biggest and most configurable section of V8's managed (aka garbage-collected) heap (i.e. where the JavaScript objects live), and the --max-old-space-size flag controls its maximum size. As memory consumption approaches the limit, V8 will spend more time on garbage collection in an effort to free unused memory.
    If heap memory consumption (i.e. live objects that the GC cannot free) exceeds the limit, V8 will crash your process (for lack of alternative), so you don't want to set it too low. Of course, if you set it too high, then the additional heap usage that V8 will allow might cause your overall system to run out of memory (and either swap or kill random processes, for lack of alternative).
    In summary, on a machine with 2GB of memory I would probably set --max-old-space-size to about 1.5GB to leave some memory for other uses and avoid swapping.
    [Source Stackoverflow](https://stackoverflow.com/a/48392705)

    ## References

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
  6. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -12,3 +12,4 @@ node --help --v8-options | grep -B 2 -A 2 max-old-space
    ## References

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
    - [NodeJS Documentation](https://nodejs.org/docs/latest-v12.x/api/cli.html#cli_node_options_options)
  7. @tjunghans tjunghans revised this gist Mar 10, 2020. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,8 @@ node --help --v8-options | grep -B 2 -A 2 max-old-space
    --max-old-space-size (max size of the old space (in Mbytes))
    type: size_t default: 0
    --initial-old-space-size (initial old space size (in Mbytes))
    ```
    ```

    ## References

    - [Can we document --max_old_space_size or is it deprecated?](https://github.com/nodejs/node/issues/7937)
  8. @tjunghans tjunghans created this gist Mar 10, 2020.
    10 changes: 10 additions & 0 deletions node-v8-max-old-space-size.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # Node V8 Option max-old-space-size

    ```
    node --help --v8-options | grep -B 2 -A 2 max-old-space
    --experimental-new-space-growth-heuristic (Grow the new space based on the percentage of survivors instead of their absolute value.)
    type: bool default: false
    --max-old-space-size (max size of the old space (in Mbytes))
    type: size_t default: 0
    --initial-old-space-size (initial old space size (in Mbytes))
    ```