简体   繁体   中英

How to get the value of max_old_space_size from the code?

As I understand it is possible to set a maximum memory usage limit for an application like this:

node --max_old_space_size=500 app.js

Is it possible to get a value of the max_old_space_size from the code?

UPDATE

With the help of @Grégory NEUT we found out that v8.getHeapStatistics() contains a field heap_size_limit which looks like what I am looking for.

However I'm still not sure about it since I didn't find any official documentation (or some piece of code from Node.js) which will approve this theory.

I also don't understand why heap_size_limit becomes 557842432 bytes ( 557.8 MB) when I set max_old_space_size to 500 MB

In the Node.js v9.4.0 Documentation you can find the function v8.getHeapStatistics() that gives you the heap size information.

UPDATE 2019 : Node.js v11.x Documentation


LEQADA Example from the comment:

For max_old_space_size=500

heap_size_limit : 557842432

total_available_size : 548898944


For max_old_space_size=900

heap_size_limit : 977272832

total_available_size : 968329344


在此处输入图片说明


EDIT : process.memoryUsage() do not give informations about the max size of the heap


In the Node.js v9.4.0 Documentation you can find the function process.memoryUsage() that gives you the heap size information.

UPDATE 2019 : Node.js v11.x Documentation

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM