Node Memory Control

Source: Internet
Author: User

    • Node can only use partial memory for the following reasons:
      Node builds on V8, and V8 's memory management mechanism limits the amount of memory used.
      In practical use, accidentally touching this memory limit will cause the process to exit.
      V8 is allocated through the heap, the memory of the objects used is allocated to the heap when the object is declared and assigned values in code, and if the requested heap free memory is not sufficient to allocate new objects, the heap memory will continue to be requested until the heap size exceeds V8
      Limit.
      Why do V8 limit the heap size? The reason is that the V8 garbage collection mechanism is limited.
      Garbage collection causes JavaScript threads to pause execution, memory is too large, garbage collection takes too long, and at that time, the heap memory size is directly limited.
      This memory limit can be opened, and node passes--max-old-space-size or--max-new-space-size at startup to adjust the size of the memory limit, as shown in the following example:
      node --max-old-space-size=1700 test.js
      Or
      node --max-new-space-size=1024 test.js
      The above parameters take effect when the V8 is initialized and can no longer be changed dynamically once it is in effect.

    • Garbage collection mechanism of V8
      V8 's garbage collection strategy is primarily based on 分代式垃圾回收机制 .
      In V8, memory is mainly divided into 新生代 老生代 two generations.
      The overall size of the V8 heap is the memory space used by the new generation plus the memory space used by the Laosheng generation.
      Default allocated memory Size:

system \ Health Generation Laosheng Generation Cenozoic (default) Cenozoic (max)
64-bit system 1400MB 32MB 64MB
32-bit system 700MB 16MB 32MB

Node Memory Control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.